#[unstable(feature = "bool_to_option", issue = "64260")]
#[inline]
pub fn then_some<T>(self, t: T) -> Option<T> {
- if self {
- Some(t)
- } else {
- None
- }
+ if self { Some(t) } else { None }
}
/// Returns `Some(f())` if the `bool` is `true`, or `None` otherwise.
#[unstable(feature = "bool_to_option", issue = "64260")]
#[inline]
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
- if self {
- Some(f())
- } else {
- None
- }
+ if self { Some(f()) } else { None }
}
}