Causing problems with Rust traits (then fixing them)
source link: https://www.youtube.com/watch?v=sNyEgAGkDN8
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
18 Comments
Read more 2 weeks ago
Just this week I was annoyed at the need for boxing and dynamic dispatch in many cases, and was thinking about how to solve it.
I was actually considering essentially creating enum_dispatch.
Well, and some shit that's probably not possible or would break all kinds of security guarantees, a kind of dynamic dispatch on stack objects, where instead of the enum discriminator you'd have the vtable pointer, and after that it would behave like a enum, with enough size for the largest variant.
But since I likely don't have the knowledge to pull that off, even if it's possible without extending rustc, since this likely would not be faster than enum variants, and since this would cause issues when converting these values back to known types, I eventually came to the conclusion that simple enums with some kind of automatic trait implementation, probably macro based, for a common trait would be the best solution.
Thats where I was, in all likelyhood it wouldn't have gone further, but now I learn that OF COURSE someone already implemented it. Even if it is a bit of a downer, on the bright side, it means I choose a decent implementation approach, and I can use this crate without having to figure it out myself (which would've took a long time, or never happened).
So thanks for enlightening me!
Read more 2 weeks ago (edited)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK