]>
git.proxmox.com Git - rustc.git/blob - src/libcore/bool.rs
6 /// Returns `Some(t)` if the `bool` is `true`, or `None` otherwise.
11 /// #![feature(bool_to_option)]
13 /// assert_eq!(false.then(0), None);
14 /// assert_eq!(true.then(0), Some(0));
16 #[unstable(feature = "bool_to_option", issue = "64260")]
18 pub fn then
<T
>(self, t
: T
) -> Option
<T
> {
26 /// Returns `Some(f())` if the `bool` is `true`, or `None` otherwise.
31 /// #![feature(bool_to_option)]
33 /// assert_eq!(false.then_with(|| 0), None);
34 /// assert_eq!(true.then_with(|| 0), Some(0));
36 #[unstable(feature = "bool_to_option", issue = "64260")]
38 pub fn then_with
<T
, F
: FnOnce() -> T
>(self, f
: F
) -> Option
<T
> {