Avoiding repeated match when dispatching a fieldless enum to types
The Rust Programming Language Forum
Avoiding repeated match when dispatching a fieldless enum to types
I’m looking for feedback on a pattern for doing type-based dispatch from a fieldless enum. The situation is roughly this: #[derive(Clone, Copy)] enum MyEnum { VarA, VarB, } struct VarA; struct VarB; trait MyVarTrait { fn do_trait() {} } impl MyVarTrait for VarA {} impl MyVarTrait for VarB {} trait Executable { fn execute<T: MyVarTrait>(self); } impl MyEnum { fn do_a_plus_b_twice(self, a: i32, b: i32) { struct Op(i32, i32); impl Executable for Op { ...
0 comments
No comments yet.