5 /// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html),
6 /// or `None` otherwise.
11 /// #![feature(bool_to_option)]
13 /// assert_eq!(false.then_some(0), None);
14 /// assert_eq!(true.then_some(0), Some(0));
16 #[unstable(feature = "bool_to_option", issue = "80967")]
17 #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
19 pub const fn then_some<T>(self, t: T) -> Option<T>
23 if self { Some(t) } else { None }
26 /// Returns `Some(f())` if the `bool` is [`true`](../std/keyword.true.html),
27 /// or `None` otherwise.
32 /// assert_eq!(false.then(|| 0), None);
33 /// assert_eq!(true.then(|| 0), Some(0));
35 #[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
36 #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
38 pub const fn then<T, F>(self, f: F) -> Option<T>
40 F: ~const FnOnce() -> T,
43 if self { Some(f()) } else { None }