General discussion of The Rust Programming Language| The Rust Programming Language Forum
Maintainer of Tokio.| The Rust Programming Language Forum
I'm happy to share the release of Kairos Gateway v0.2.10 - a high-performance, multi-protocol API gateway built with Rust and Actix-Web. What is Kairos Gateway? Kairos is a production-ready API gateway that routes and load-balances traffic across multiple protocols with enterprise-grade features. Think of it as a lightweight, fast alternative to Kong or NGINX Plus, written entirely in Rust. Key Features Multi-Protocol Support: HTTP, WebSocket (ws:// & wss://), FTP, and DNS in a single gateway...| The Rust Programming Language Forum - Latest posts
I'm using Rust to write code for an embedded target of mine -- a CPU made on a digital circuit simulator, implementing a subset of Thumb (specifically, thumbv6m-none-eabi). The CPU is slow (~40kHz) so every wasted instruction adds up to a noticeable slowing down of stuff I run. I understand this is nowhere near anything Rust was designed to run on. There is something I'm blocking on: all functions, even leaves, have a frame pointer, which I don't need. For example, here's a small function tha...| The Rust Programming Language Forum - Latest posts
Hi everyone! I've been working with blockchain technologies for a long time, and I decided to switch to Rust and continue my career with it. To practice and improve my skills, I developed a minimal blockchain Peer-to-Peer (P2P) node - Blocksmith. I would highly appreciate any review of my project on how to make my code more idiomatic, how to optimise it, and how to improve it. It is currently an MVP with core functionality implemented. I already see how to enhance the functionality of my proj...| The Rust Programming Language Forum - Latest posts
Are you talking about mlock / MAP_LOCKED? mlock forces the file to be in RAM even if nobody else changes the file so that would defeat the purpose of memory mapping (at least in my use case). Or is it some other flag? Doesn't all static data have the same problem we're talking about? Static data is mmaped from the compiled executable file by the operating system. A user might modify the executable file at runtime, thus changing static data that is assumed to not change. But I guess the answer...| The Rust Programming Language Forum - Latest posts
You should absolutely try to use rustc_public if you can. That's designed to be consumed in a less-breaks-all-the-time way by external tools. If you need help, check out #project-stable-mir on Zulip.| The Rust Programming Language Forum - Latest posts
Hi everyone! I'm writing a "Grafana for your personal data" app in Dioxus, and I'd appreciate a code review! The idea behind the app is to store personal data and find correlations between them, for example, calculating your average heart rate during workouts based on your food intake, sleep, etc., or more social data, such as your mood based on the number of hours you spend at the computer. In principle, correlations between any values can be traced. I'm interested in this project for ...| The Rust Programming Language Forum - Latest posts
I have an axum async handler as follows (simplified): async fn put_handler(Path(method_id): Path<u16>, Query(params): Query<Params>, header_map: HeaderMap, body: Bytes) -> impl IntoResponse { if CACHES.put(method_id, params.key.unwrap(), params.value,unwrap()).is_ok() { StatusCode::OK } else { StatusCode::INTERNAL_SERVER_ERROR } } 'CACHES.put' is ultrafast, in the nanoseconds range. That's why is sync. It only performs a 'put' in a cache and sets the params.value content to a in-memory buffer...| The Rust Programming Language Forum - Latest posts
Hi everyone! I would like to ask for a code review of my project Distributed job queue with RabbitMQ, here is the link GitHub - Manyuta/rustq at dev. It is in the dev branch so far. This is the final project of my rustcamp journey organized by the Ukrainian Rust Community. The project is a distributed job queue built with: RabbitMQ for queue management Redis for job storage and metadata Tokio for concurrency (I used Semaphore to control it) 100% Rust, using lapin and deadpool-redis It support...| The Rust Programming Language Forum - Latest posts
Thanks for the reply! Yes hardcoding the actual value of <i32 as FromByteRepr>::Size works, but the purpose of this example was to spec out a derive macro for this trait, so i32 is just meant to represent some arbitrary concrete type (which the macro would not know the actual instantiation of). I will try your second example, thanks. Is this a known compiler bug? Is there somewhere I should report it?| The Rust Programming Language Forum - Latest posts
So a struct that's supposed to be mutable can just never contain fields whose type has a lifetime parameter? In my particular case, it is even more frustrating, because all the (referenced) data is in fact owned by the same struct, and thus all of the lifetimes are more or less tied together (though obviously the compiler doesn't/cant't understand that). To continue with my abstract examples, imagine that the FromExternalLibrary struct actually looks like this: pub struct FromExternalLibrary<...| The Rust Programming Language Forum - Latest posts
In the future it should be more convenient: Tracking Issue for `Vec::recycle` · Issue #148227 · rust-lang/rust · GitHub| The Rust Programming Language Forum - Latest posts
i have a situation along the line of impl Trait1 for A{ fn myfunc(&mut self){ ................. ::fn(self) //if and only if A:Trait2 ................. } } i think i can probably find a workaround to do that but i was wondering if anyone knows of a clean maintainable solution for something like this ideally without runtime costs| The Rust Programming Language Forum
For some application I need a permutation of three positions of a slice. Currently, I do this as follows: fn permute3a<E>(lst: &mut [E], a: usize, b: usize, c: usize) { lst.swap(b, c); lst.swap(a, b); } This moves the element at a to b, b to c and c to a. But I guess that doing two swaps is not the optimal solution for this problem. I would think that implementation would look like: fn permute3b<E: Copy>(lst: &mut [E], a: usize, b: usize, c: usize) { let tmp = lst[c]; lst[c] = lst[b]; lst[b] ...| The Rust Programming Language Forum - Latest posts
Hello (Rust) World! Please can anyone share links to useful resources that will help a total beginner to learn to programme in Rust? I am said 'total beginner', and I am planning a project to create an online course "Learn Rust with me" in which I teach the Rust programming language from a first principles perspective, on the basis that course participants will be able to 'learn as I learn, fail as I fail and learn from our mistakes together'. Essentially I want to make a Rust course that is ...| The Rust Programming Language Forum - Latest posts
The documentation for Context says that Currently, Context only serves to provide access to a &Waker which can be used to wake the current task. Is Context ever going to provide more? Relatedly, in typical implementations of select, when the future is polled, it must internally poll every future it manages because the wakeup has no additional information about which future woke it up. Why doesn't poll take an extra argument (or Context contain something) to remedy this? Did the Future trait w...| The Rust Programming Language Forum - Latest posts
I want to add some dependencies to workspace.dependencies then add them to a certain package.I've been searching the internet but didn't find anything that could help. Now I have to call cargo add xxx on a package, waiting cargo to generate the code, cutting the generated code and paste it to Cargo.toml file at workspace root, then add xxx.workspace = true back to the Cargo.toml file at that package. So I wonder if a command like cargo add xxx --workspace to add dependencies to workspace. Tha...| The Rust Programming Language Forum - Latest posts
I am creating an application using Rust + GTK4 + libadwaita and currently in the process of creating some launcher arguments using std::env::args(), testing it using an argument --trace. When I build and run my project (compile resources and then cargo run -- --trace), the program fails with Unknown option --trace. Here is my code for the argument parsing: use simple_logger::SimpleLogger; fn main() { let args = std::env::args().skip(1); for arg in args { match arg.as_str() { "--trace" => { pr...| The Rust Programming Language Forum - Latest posts
Here's what I'm trying to achieve: // I wish to dereference this into any GenericFields<U> where T: Deref<Target = U>. struct GenericFields<T> { a: T, b: T, c: T, } impl<T: Deref> Deref for GenericFields<T> where <T as Deref>::Target: Sized, { type Target = GenericFields<<T as Deref>::Target>; fn deref(&self) -> &Self::Target { todo!() } } Unfortuantly I can't figure out if this is possible. Is it both possible, and if so, how can i achieve it? Here's a longer example to give context if neede...| The Rust Programming Language Forum - Latest posts
Along the same lines as the suggestion for VHDL, have a look as OpenSCAD. It's a 3D modeling language. I learned it when I found that I couldn't get on with Blender. There's common points with Rust in that variables are immutable but it goes further -- almost as far as being functional. And if you've got access to a 3D printer, you can hold the output of your program in your hand.| The Rust Programming Language Forum - Latest posts
@simonbuchan Indeed no, nanosecond accuracy is not needed in music sequencing applications, for which I primarily designed the ticker. After all, human musicians can't achieve anything near that. Following your tip, I am now using Rayon for spawning. My ticker, together with its FFI and C# wrappers, are now available on GitHub at Millisecond Ticker: High Resolution Ticker for .Net using Rust. Here is the current code of the ticker module. Validation is minimal, as that is taken care of more f...| The Rust Programming Language Forum - Latest posts
I don’t know enough about this topic to offer good advice, other than to mention bumpalo. When I make a new crate, the first thing I always do is search for existing crates in the same area. In this case, find existing arena allocators and existing crates which implement the allocator API, and read their source code for ideas. Another piece of advice - seeing entire function bodies in unsafe makes me cringe a little. I hope that that’s just a prototype. I’m a big fan of having 1 unsafe ...| The Rust Programming Language Forum - Latest posts
I don't understand what you mean there. Are you saying that my Rust + SSD is not Rust any more? Surely not.| The Rust Programming Language Forum - Latest posts
Hello, I have a single core Corext-M4 chip and I wonder, if some code pends an interrupt and then it executes, is there already a happen-before relationship, or I need to establish another one? What if interrupt was already pended but the context I currently at is supressing the interrupt and I pend it again? Does it even matter on those 1 core devices?| The Rust Programming Language Forum - Latest posts
Simply am summarizing some of my findings with regards to Rust based on exploring OS and shell options in recent years. Linux does appear to be the optimal environment for development using Rust. Linux has UTF-8 efficiency in the core kernel (e.g. not fixed wide-chars). Rust 1.90 has lld on Linux, for build performance and ext4 has the edge over brtfs, NTFS (and ZFS, e.g. BSD) Linux kernel using Rust relatively aggressively. Rust FFI relatively robust on Linux Last but not least, in the Linux...| The Rust Programming Language Forum - Latest posts
AFAIK LLVM doesnt provide any method you can write to zero and considers it UB, except inline assembly and null-pointer-is-valid. But I'm not sure about any addresses except 0. Related: What about: Targets where NULL is a valid pointer · Issue #29 · rust-lang/unsafe-code-guidelines · GitHub --- By the way, Rust you can abort on basically any target with an undefined instruction or a wash trap. There is also that proposal: abort in core · Issue #442 · rust-lang/libs-team · GitHub| The Rust Programming Language Forum - Latest posts
You mean, an unimplemented feature, with inadequate test coverage (subsequently rectified), broke a use case depending on that feature? The horror! Releasing software for wider use, where it's subjected to scenarios which can't be captured by test suites, however comprehensive, is the way to improve robustness. And that's precisely what Canonical has done. Of course the vocal opposition is on hair trigger to proclaim that the bug invalidates the entirety of the uutils project, since that fits...| The Rust Programming Language Forum - Latest posts
Thanks guys. It seems to me that the statement A trait can be implemented for a range of different types. Your default implementation for rank() trait method assumes it is safe to convert to u8 from type T that trait Simple is implemented for. The compiler can't guarantee this. from burumdev is correct. I tried the crate repr-discriminantfrom Schard in verious ways, but I was unable to get that functionality working as a default Trait function. cheers, Willem| The Rust Programming Language Forum - Latest posts
I have a struct which consists of 29 f64 fields, all but 2 of which are Optional. Serde works great, but it produces a lot of code, all up 19.5KB for this struct. Is that expected? It seems like a lot for what is a very simple and repetitive struct. I made a manual deserialiser based on the example. And while it doesn't quite have all the same error protections (I'm not doing anything if the two non-optional fields are missing, leaving them as default values instead) it's a lot smaller, only ...| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
Image compression tinkerer https://octodon.social/@rust https://lib.rs| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
I am currently learning about graphics-related knowledge. Regarding color, I have the following definition, and I would like to understand the applicable scenarios and limitations of this definition, as well as any issues from the perspective of Rust's design philosophy. Thank you all for your help. use std::marker::PhantomData; pub trait ColorSpace {} #[derive(Debug)] pub struct Srgb ; impl ColorSpace for Srgb {} pub trait Premultipliable { type Output; fn premultiply(&self) -> Self::Output;...| The Rust Programming Language Forum - Latest posts
Hello, I want to have State that I know will never borrow from View, but I can't convince the borrow checker. Adding 'static bound, which should make it clear that State cannot borrow, doesn't help. I remember similar issue but with opaque types: `impl Trait + 'static` is not `'static` if returned from a generic function · Issue #76882 · rust-lang/rust · GitHub. Edit: I replaced &mut with &, error still holds. I hoped that maybe using interior mutability as a workaround. Code (playground):...| The Rust Programming Language Forum - Latest posts
Thanks for asking. I have not managed to solve the issue. Even setting the root dir manually as suggested on the lspconfig github page didn't work, which is rather strange. I am going to try rustacean next, but my day job has been taking up all my time.| The Rust Programming Language Forum - Latest posts
From what I have just learned, the `global_allocator` attribute has some magic: it can be used anywhere to define a global allocator, even deep inside a private unused module of a dependency of a dependency the defined global allocator will be called implicitly, i.e., your crate will be affected if it has a dependency which defines the global allocator, even if your crate doesn’t call any function from that dependency as far as I know, there is no way to check what global allocator I’m us...| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
I'm working on a driver for a device called the Tourbox, for Linux specifically. I have a working version, which uses udev rules to start the driver process whenever it detects the device connects. The issue with this approach is udev only detects the device when it's plugged in. If it's already connected at boot, nothing happens. Ideally, too, I'd rather have the driver process run constantly in the background to make configuration and error reporting more consistent. The Tourbox exposes its...| The Rust Programming Language Forum
I am looking for the author of a crate I am using. The crate is tk v0.1.10 (crates.io: Rust Package Registry). I have some questions I would to ask. There is no contact info on his github account and there does not seem to be any activity since April of 2024. If anyone has any ideas about how to contact this person, I would be grateful.| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
I have this open source rust project that I started in 2022 that's very central to my smart home setup: thomas351 / rust-influxdb-udp-logger · GitLab I've got multiple instances of it running on various devices, but the most important instance doing most of the work is nowadays running on this Intel N100 mini PC powered by Linux Mint 22.1. It's running stable and does what it's meant to do, but it uses more CPU cycles than I wish it would (40-50% of one of my 4 CPU cores, according to htop) ...| The Rust Programming Language Forum
i want to learn advanced data structures like trees and graphs and etc. i want some resource to learn about data structures specifically in rust because of the specific rules of the borrow checker, how to create them and the best practices to use. i know a lot of resources for data structures exercises in rust, but no book/website to learn how they work.| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
Why was &mut x chosen over mut &x for mutable references? I find the syntax &mut x for mutable references less readable than a hypothetical mut &x. With &x, the & is directly before the variable name, clearly indicating a reference. Adding mut to form mut &x would preserve this structure, keeping & next to the variable for better visual consistency and easier scanning. However, &mut x shifts & left and introduces a space, making it harder to quickly recognize the reference. Were there histori...| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
The code below (and in Playground) let v = vec![3i32, 2i32].iter(); println!("{}", v.sum::()); Errors due to a temporary being dropped. I expected this would convert to something close to (but the last example contradicts it): let v = { let _tmp =vec![3i32, 2i32]; <[_]>::iter(&_tmp[..]) }; // underlying data is dropped after we exit block expression But if that were the case, should happen the same here? let f = move |a| a; let v = f(&6); println!("{v}") But t...| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
I have recently been working on a GPIO/I2C library for the RPI and have been trying to come up with a good method for keeping track of which GPIO pins are in use. Specifically for things like serial communication (i.e. I2C, SPI, ect.). I was thinking that I could use an array and put the pins in use into that but I'm worried that that might be bad practice. The important thing to remember is that I can't use the std library because this is for embedded programming and their is no OS. I also c...| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
I tried to make this example as minimal as I could. It seems very clear that within the impl Property for MyProperty, Self::State should always be the same type as MyState, but the compiler doesn't seem to know that. Reframing the trait as T: HasStateFor makes the error go away. use std::marker::PhantomData; trait CanGetStateFrom: Property { fn get_state(input: &mut T) -> &mut Self::State; } trait Property { type State; fn update_state(state_source: &mut T) whe...| The Rust Programming Language Forum
Thank you for the idea. I made slightly different implementation based on it: playground The usage is as follows: // simple types impl MyMainTrait for i32 { type BlanketType = SimpleType; } impl MyMainTrait for &str { type BlanketType = SimpleType; } // struct types struct Foo { field: i32, } impl MyMainTrait for Foo { type BlanketType = StructType; } impl StructTrait for Foo { const FIELDS: &'static [&'static str] = &["field"]; fn do_somethin...| The Rust Programming Language Forum
Recently I found a case where rust's type inference fails for collections of trait objects. Here an example: use std::fmt::Debug; #[derive(Debug)] struct D1; #[derive(Debug)] struct D2; fn debug_vec() -> Vec> { // compiler: hmm, I don't know what type this is. Let's see how this one // unfolds. let mut v = Vec::new(); // compiler: got it, v must be Vec>! v.push(Box::new(D1)); // compiler: gosh darn it, this is no Box add...| The Rust Programming Language Forum
i'm looking for something like golang's fs.FS interface, but for rust. I've seen a few crates for this, such as filesystem and vfs, but nothing as flexible or generic. am i missing something?| The Rust Programming Language Forum
This is a companion discussion topic for the Async Interviews that I am discussing. As the introductory blog post clarifies, the goal of these interviews is primarily to help answer the question, "Now that async-await is stable, what should we do next?" But it's also just to have fun talking about Async I/O and Rust and exploring what the ecosystem has to offer. Collected links to the blog posts and videos: Async Interview #1: Alex and Nick talk about async I/O and WebAssembly (video) Async ...| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum