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
Methods sometimes need access to the Arc managing self. This is easy: fn f(self: Arc) (to own the reference count) or fn f(self: &Arc) (to borrow it with the possibility of owning a count later by clone()). The former has the issue that every method call consumes self so many calls need o.clone().f() which is very unergonomically and it's slower because of the forced atomic inc/dec. But the &Arc version works, so whatever. However, if I want to pass around an Arc, then...| The Rust Programming Language Forum
General discussion of The Rust Programming Language| The Rust Programming Language Forum
This is not a real problem that I have, but I was thinking on how similar functionality can be implemented in Rust. I have an application struct, which owns other subsystems, such as the Executor. I want to be able to push closures to the executor, which contain references to the application struct. Essentially I want to have my own scoped closures, similar to scoped threads in std. As in the following example. What are the safe ways to implement this? I want the App to specifically not be wr...| The Rust Programming Language Forum
Hi, Is it possible by using serde/serde_json to deserialize struct that has raw ptr as a member? The deserialization should assign null to that member? Thank you| The Rust Programming Language Forum
I want to emphasize here that an uninhabited type isn't quite a zero sized type; it's generally fine to treat them as such, but ideally size_of() would be returning that it has no size at all, not even a size of 0. There's a related situation with dynamically sized types like dyn Foo and [Bar] (without a wrapping reference) - it's not documented, but IIRC size_of() panics for those as 0 is not a reasonable fallback? Logically, it should probably return an enum itself!| The Rust Programming Language Forum
I made a library that's used by a larger application. The application calls some function of my library, which is blocking. Currently, you cannot interrupt the application while my library's code is running. I want to be able to terminate my library with Ctrl+C, which should: Run some cleanup actions, including killing a process, starting a process, and writing to files. This does not need to be interruptible; e.g. a second Ctrl+C does not need to do anything. Return an Err(Error::Interrupted...| 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
How can I correctly declare type inside declarative macro by separating type's name itself and it's generics ? Consider this example: struct RectangleA; struct RectangleB; I want to separate type declaration (and possibly it's genercics) between few macroses to match on different parameters. I see it like this: macro_rules! get_type { (false) => { RectangleA } (true) => { RectangleB ...| The Rust Programming Language Forum