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?
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.
-
-
Yeah alright, thought there would be a related static technique
-
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.
- 9 more replies
New conversation -
-
-
s/write to/choose/ E.g. fn foo() -> Result<(), Box<dyn Error>> {} It means we don't know statically which error we might get back, but we guarantee it'll implement the Error trait. Less efficient, but super useful when you need it.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
From what I know Julia compiles specialised versions for each method signature that it encounters (also over more broad reaching types) and then it may inline those on hot paths. But it’s long ago since I looked at any of this so I may be wrong
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
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.