3 use crate::marker::Destruct;
6 /// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html),
7 /// or `None` otherwise.
12 /// #![feature(bool_to_option)]
14 /// assert_eq!(false.then_some(0), None);
15 /// assert_eq!(true.then_some(0), Some(0));
17 #[unstable(feature = "bool_to_option", issue = "80967")]
18 #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
20 pub const fn then_some<T>(self, t: T) -> Option<T>
24 if self { Some(t) } else { None }
27 /// Returns `Some(f())` if the `bool` is [`true`](../std/keyword.true.html),
28 /// or `None` otherwise.
33 /// assert_eq!(false.then(|| 0), None);
34 /// assert_eq!(true.then(|| 0), Some(0));
36 #[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
37 #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
39 pub const fn then<T, F>(self, f: F) -> Option<T>
41 F: ~const FnOnce() -> T,
44 if self { Some(f()) } else { None }