use edyn::edyn; use std::marker::PhantomData; trait Constants { const EXAMPLE: u32; } struct Zero; impl Constants for Zero { const EXAMPLE: u32 = 0; } struct Five; impl Constants for Five { const EXAMPLE: u32 = 5; } #[edyn(AnyMath)] trait Math { fn get_number(&self) -> u32 where C: Constants; } struct Adder(pub u32); impl Math for Adder { fn get_number(&self) -> u32 where C: Constants, { self.0 + C::EXAMPLE } } struct MultiplierWith { _phantom: PhantomData<*const C2>, } impl Math for MultiplierWith { fn get_number(&self) -> u32 where C: Constants, { C2::EXAMPLE * C::EXAMPLE } } #[edyn] enum AnyMath { Adder, FiveMultiplier(MultiplierWith), } #[test] fn main() { let two_adder: AnyMath = Adder(2).into(); let five_multiplier: AnyMath = MultiplierWith:: { _phantom: PhantomData, } .into(); assert_eq!(two_adder.get_number::(), 2); assert_eq!(two_adder.get_number::(), 7); assert_eq!(five_multiplier.get_number::(), 0); assert_eq!(five_multiplier.get_number::(), 25); }