4 ms·
Fortunately in Rust you can have it both ways, as in `Type::Variant` most of the time and `use Type::Variant; … Variant …` in cases where the type name just cau
by robjwells 2y ago
Fortunately in Rust you can have it both ways, as in `Type::Variant` most of the time and `use Type::Variant; … Variant …` in cases where the type name just causes noise.
Example in the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=455792818473fba5587d8876b8d4e87d https://play.rust-lang.org/?version=stable&mode=debug&editio...
- hardwaresofton 2y agoI’ve never done this but this is a great point. I think I’d avoid doing this though because variants often have really short, reusable/general names (leaning into the overall type name being close)
- GrantMoyer 2y agoYou can put the use statement in the function with the match, or even limit the scope further: { use MyEnum::*; match my_enum {…} }