1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
trait Some where Self: Sized { fn some(self) -> Option<Self> { Some(self) } } impl<T> Some for T {} #[cfg(test)] mod tests { use crate::Some; #[test] fn it_works() { assert_eq!(4.some(), Some(4)); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
trait Some where Self: Sized { fn some(self) -> Option<Self> { Some(self) } } impl<T> Some for T {} #[cfg(test)] mod tests { use crate::Some; #[test] fn it_works() { assert_eq!(4.some(), Some(4)); } }