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
I remember in Julia they called this multiple dispatch
1 reply 0 retweets 0 likes -
Replying to @emilbayes
Ah, so that's something different! Dynamic dispatch is when there's multiple arguments that fit a trait implementation, and during Runtime it's chosen which one to write too. This is marked with `dyn` in Rust. The thing I'm talking about is (I think) only a compile-time thing.
3 replies 0 retweets 0 likes -
Replying to @yoshuawuyts
Yeah alright, thought there would be a related static technique
1 reply 0 retweets 1 like -
Replying to @emilbayes
Oh yeah, the related static version would be: fn foo(arg: impl SomeTrait) {} What I'm talking about is: impl<T: Debug> Foo {} impl<T: Debug + Display> Foo {} Ths is not allowed because the implementations overlap. But with specialization one could be picked.
2 replies 0 retweets 0 likes -
Replying to @yoshuawuyts @emilbayes
(I hope I'm doing an okay job explaining this -- just learned a bunch about this haha)
1 reply 0 retweets 0 likes -
Replying to @yoshuawuyts
Ah so it’s having it choose the most narrow definition that matches?
1 reply 0 retweets 1 like -
Replying to @emilbayes
Yeah, that's the idea! Which would allow us to do fun things like "if we read from a socket, and write to a socket, use a super efficient system call to handle it". But still keep the generic implementation for other types. This is all quite experimental still.
1 reply 0 retweets 0 likes
Also like @mountain_ghosts pointed out: "choosing the most narrow definition" could get us oddly close to a CSS specificity kind of situation, which would probably not be ideal.
Lots of stuff to figure out here still!
-
-
Replying to @yoshuawuyts @emilbayes
in general there will not be a single most-narrow matching definition
1 reply 0 retweets 1 like -
e.g. picture I have these: impl<T: Copy> Something for Vec<T> impl<T: Ord> Something for Vec<T> which do I pick for Vec<u8>
3 replies 0 retweets 1 like - 3 more replies
New conversation -
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.