1 2 3 4 5 6 7 8 9 10 11 12 13 14
pub trait OptionThenExt { type Inner; fn then(self, f: impl FnOnce(Self::Inner)); } impl<T> OptionThenExt for Option<T> { type Inner = T; fn then(self, f: impl FnOnce(Self::Inner)) { if let Some(inner) = self { (f)(inner) } } }