From c2ce5bd9a47d4ced67ce94b8ee0cbd024f4ae8ee Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 Jul 2022 11:28:14 +0100 Subject: [PATCH 1/3] remove incorrect debug assert --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- src/imp_pl.rs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5c0ae7..f685f9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - +## 1.12.1 + +- Remove incorrect `debug_assert`. + ## 1.12.0 - Add `OnceCell::wait`, a blocking variant of `get`. diff --git a/Cargo.toml b/Cargo.toml index 5c77dfc..7ff9f8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "once_cell" -version = "1.12.0" +version = "1.12.1" authors = ["Aleksey Kladov "] license = "MIT OR Apache-2.0" edition = "2018" diff --git a/src/imp_pl.rs b/src/imp_pl.rs index 2bd80fa..d80ca5e 100644 --- a/src/imp_pl.rs +++ b/src/imp_pl.rs @@ -168,6 +168,7 @@ fn initialize_inner(state: &AtomicU8, init: &mut dyn FnMut() -> bool) { None, ); }, + Err(INCOMPLETE) => (), Err(_) => debug_assert!(false), } } From 61e27f9ff512b69bbdb11df63748671f33ef241b Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 21 Jun 2022 12:41:06 +0900 Subject: [PATCH 2/3] Add a `Lazy::get` function, similar to `OnceCell::get` --- src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e02ecb1..70f08de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -741,6 +741,23 @@ pub mod unsync { None => panic!("Lazy instance has previously been poisoned"), }) } + + /// Gets the reference to the result of this lazy value if + /// it was initialized, otherwise returns `None`. + /// + /// # Example + /// ``` + /// use once_cell::unsync::Lazy; + /// + /// let lazy = Lazy::new(|| 92); + /// + /// assert_eq!(Lazy::get(&lazy), None); + /// assert_eq!(&*lazy, &92); + /// assert_eq!(Lazy::get(&lazy), Some(&92)); + /// ``` + pub fn get(this: &Lazy) -> Option<&T> { + this.cell.get() + } } impl T> Deref for Lazy { @@ -1214,6 +1231,23 @@ pub mod sync { None => panic!("Lazy instance has previously been poisoned"), }) } + + /// Gets the reference to the result of this lazy value if + /// it was initialized, otherwise returns `None`. + /// + /// # Example + /// ``` + /// use once_cell::sync::Lazy; + /// + /// let lazy = Lazy::new(|| 92); + /// + /// assert_eq!(Lazy::get(&lazy), None); + /// assert_eq!(&*lazy, &92); + /// assert_eq!(Lazy::get(&lazy), Some(&92)); + /// ``` + pub fn get(this: &Lazy) -> Option<&T> { + this.cell.get() + } } impl T> Deref for Lazy { From 2b0e3e5d8325000d84881de8eff08f0a86f3a9a6 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 5 Jul 2022 07:25:36 +0900 Subject: [PATCH 3/3] Publish 1.13.0 --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f685f9b..d5019ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - +## 1.13.0 + +- Add `Lazy::get`, similar to `OnceCell::get`. + ## 1.12.1 - Remove incorrect `debug_assert`. diff --git a/Cargo.toml b/Cargo.toml index 7ff9f8a..da8a3d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "once_cell" -version = "1.12.1" +version = "1.13.0" authors = ["Aleksey Kladov "] license = "MIT OR Apache-2.0" edition = "2018"