use std::any::Any; #[test] fn any_trait() { let u32s = FavoriteThings { thing: Box::new(10_u32), }; let _floats = FavoriteThings { thing: Box::new(50.0_f32), }; let extracted_u32 = u32s.get::().unwrap(); assert_eq!(*extracted_u32, 10); } struct FavoriteThings { thing: Box, } impl FavoriteThings { pub fn get(&self) -> Option<&T> { self.thing.downcast_ref() } }