/* [dependencies] */ mod sealed { pub trait IsType {} impl IsType for T {} } /// Trait `IsType` is implemented if and only if `Self` is `T` pub trait IsType: sealed::IsType { /// Convert from `T` to `Self` (no-op) fn identity_from(x: T) -> Self where Self: Sized, T: Sized; /// Convert from `Self` to `T` (no-op) fn identity_into(self) -> T where Self: Sized, T: Sized; } impl IsType for T { fn identity_from(x: T) -> Self where Self: Sized, T: Sized, { x } fn identity_into(self) -> T where Self: Sized, T: Sized, { self } } pub trait Functor: IsType> { type F: Functor; type A; fn fmap(self, f: F) -> Self::F where F: FnMut(Self::A) -> B; } impl Functor for Option { type F = Option; type A = T; fn fmap(self, f: F) -> Option where F: FnMut(T) -> B, { Option::map(self, f) } } fn main() { println!(""); }