From f0386a10e0112acef6ea0447e6e5a3ac1c7cb118 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 7 Sep 2019 13:16:18 +0100 Subject: Add "bool" lang item --- src/libcore/lib.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libcore/lib.rs') diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index c168d5c8a2e..03b6aa68d3c 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -198,6 +198,7 @@ pub mod borrow; pub mod any; pub mod array; pub mod ascii; +pub mod bool; pub mod sync; pub mod cell; pub mod char; -- cgit 1.4.1-3-g733a5 From 0f0e1c1691422132a40e5f534ff579004a79ef9c Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 7 Sep 2019 17:04:19 +0100 Subject: Move `libcore/bool/mod.rs` to `libcore/bool.rs` --- src/libcore/bool.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/libcore/bool/mod.rs | 47 ----------------------------------------------- src/libcore/lib.rs | 2 +- 3 files changed, 46 insertions(+), 48 deletions(-) create mode 100644 src/libcore/bool.rs delete mode 100644 src/libcore/bool/mod.rs (limited to 'src/libcore/lib.rs') diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs new file mode 100644 index 00000000000..54faa7047d5 --- /dev/null +++ b/src/libcore/bool.rs @@ -0,0 +1,45 @@ +//! impl bool {} + +#[cfg(not(boostrap_stdarch_ignore_this))] +#[lang = "bool"] +impl bool { + /// Returns `Some(t)` if the `bool` is `true`, or `None` otherwise. + /// + /// # Examples + /// + /// ``` + /// #![feature(bool_to_option)] + /// + /// assert_eq!(false.then(0), None); + /// assert_eq!(true.then(0), Some(0)); + /// ``` + #[unstable(feature = "bool_to_option", issue = "0")] + #[inline] + pub fn then(self, t: T) -> Option { + if self { + Some(t) + } else { + None + } + } + + /// Returns `Some(f())` if the `bool` is `true`, or `None` otherwise. + /// + /// # Examples + /// + /// ``` + /// #![feature(bool_to_option)] + /// + /// assert_eq!(false.then_with(|| 0), None); + /// assert_eq!(true.then_with(|| 0), Some(0)); + /// ``` + #[unstable(feature = "bool_to_option", issue = "0")] + #[inline] + pub fn then_with T>(self, f: F) -> Option { + if self { + Some(f()) + } else { + None + } + } +} diff --git a/src/libcore/bool/mod.rs b/src/libcore/bool/mod.rs deleted file mode 100644 index 0fbd3b8c2bb..00000000000 --- a/src/libcore/bool/mod.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! impl bool {} - -#![stable(feature = "core_bool", since = "1.39.0")] - -#[cfg(not(boostrap_stdarch_ignore_this))] -#[lang = "bool"] -impl bool { - /// Returns `Some(t)` if the `bool` is `true`, or `None` otherwise. - /// - /// # Examples - /// - /// ``` - /// #![feature(bool_to_option)] - /// - /// assert_eq!(false.then(0), None); - /// assert_eq!(true.then(0), Some(0)); - /// ``` - #[unstable(feature = "bool_to_option", issue = "0")] - #[inline] - pub fn then(self, t: T) -> Option { - if self { - Some(t) - } else { - None - } - } - - /// Returns `Some(f())` if the `bool` is `true`, or `None` otherwise. - /// - /// # Examples - /// - /// ``` - /// #![feature(bool_to_option)] - /// - /// assert_eq!(false.then_with(|| 0), None); - /// assert_eq!(true.then_with(|| 0), Some(0)); - /// ``` - #[unstable(feature = "bool_to_option", issue = "0")] - #[inline] - pub fn then_with T>(self, f: F) -> Option { - if self { - Some(f()) - } else { - None - } - } -} diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 03b6aa68d3c..690cff483b0 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -198,7 +198,6 @@ pub mod borrow; pub mod any; pub mod array; pub mod ascii; -pub mod bool; pub mod sync; pub mod cell; pub mod char; @@ -228,6 +227,7 @@ pub mod task; pub mod alloc; // note: does not need to be public +mod bool; mod tuple; mod unit; -- cgit 1.4.1-3-g733a5