I think what I want is specialization in Rust. But I'm not sure if that's actually what I want. E.g. I want to be able to define some method. But then if certain conditions apply define a different, more efficient method with the same signature. That's... specialization right?
-
-
Replying to @yoshuawuyts
so instead of fn foo() { if condition { // ... } else { // ... } } it's a compile-time thing, like: #[cfg(condition)] fn foo() { /* ... */ } #[cfg(not-condition)] fn foo() { /* ... */ }
2 replies 0 retweets 1 like -
-
Replying to @mountain_ghosts
Ah, so I was more thinking along the lines of having more specific impls for specific trait bounds. E.g. impl<T: AsyncRead> Socket<T> { from_reader(t: T) -> Result<Self>; } impl Socket<File> { from_reader(t: File) -> Result<Self>; } #2 could likely be more optimized
1 reply 0 retweets 0 likes -
Replying to @yoshuawuyts @mountain_ghosts
This might work for concrete types already (haven't checked, believe there's some cases in which it works). But I believe you can't specify more specific trait bounds for T that's not a concrete type.
2 replies 0 retweets 0 likes
My theoretical knowledge around this stuff is still... not great -- I feel like I know what I want, but not confident in which constraints currently exist.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.