1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
pub trait ResultFn { type Result; fn result(self) -> Self::Result; } impl ResultFn for () { type Result = (); fn result(self) {} } pub struct Id<T> (T); impl<T> ResultFn for Id<T> { type Result = T; fn result(self) -> T { self.0 } } impl<T> Id<T> { pub fn new(v: T) -> Self { Self(v) } }