3 use crate::marker::Destruct;
7 /// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html),
8 /// or `None` otherwise.
13 /// #![feature(bool_to_option)]
15 /// assert_eq!(false.then_some(0), None);
16 /// assert_eq!(true.then_some(0), Some(0));
18 #[unstable(feature = "bool_to_option", issue = "80967")]
19 #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
21 #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
22 pub const fn then_some<T>(self, t: T) -> Option<T>
24 T: ~const Drop + ~const Destruct,
26 if self { Some(t) } else { None }
29 /// Returns `Some(f())` if the `bool` is [`true`](../std/keyword.true.html),
30 /// or `None` otherwise.
35 /// assert_eq!(false.then(|| 0), None);
36 /// assert_eq!(true.then(|| 0), Some(0));
38 #[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
39 #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
41 #[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
42 pub const fn then<T, F>(self, f: F) -> Option<T>
44 F: ~const FnOnce() -> T,
45 F: ~const Drop + ~const Destruct,
47 if self { Some(f()) } else { None }