4 ms·
You actually can have a single queue that handles the different cases. You want dynamic dispatch for that, the syntax looks like this (quick addition to the pla
by dwattttt 6y ago
You actually can have a single queue that handles the different cases. You want dynamic dispatch for that, the syntax looks like this (quick addition to the playground sample): https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=65c322cf17745d855c348e65eb3d0284 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- rst 6y ago... which does put both cars and bicycles in the same queue, but doesn't eliminate the copy-paste for each new type completely; 'car' and 'bicycle' still wind up with separate 'get_speed' impls, which are textually identical aside from the type names.
- cyphar 6y agoUsually the way people solve this in Rust is with macros.
- Tyr42 6y agoSure, traits talk about functions, not properties/ strict fields, so you need to provide trivial getters if you want to abstract over properties. True, but not that interesting? Sure we could have some Ruby :get_attrs magic or whatever.