1 2 3 4 5 6 7 8 9 10 11 12
pub trait BoolExt { fn and_then<T>(self, f: impl FnOnce() -> Option<T>) -> Option<T>; } impl BoolExt for bool { fn and_then<T>(self, f: impl FnOnce() -> Option<T>) -> Option<T> { match self { true => f(), false => None, } } }