diff options
Diffstat (limited to 'library/std/src/sync/once_lock.rs')
-rw-r--r-- | library/std/src/sync/once_lock.rs | 59 |
1 files changed, 22 insertions, 37 deletions
diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index ed339ca5d..ab25a5bcc 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -14,8 +14,6 @@ use crate::sync::Once; /// # Examples /// /// ``` -/// #![feature(once_cell)] -/// /// use std::sync::OnceLock; /// /// static CELL: OnceLock<String> = OnceLock::new(); @@ -32,7 +30,7 @@ use crate::sync::Once; /// assert!(value.is_some()); /// assert_eq!(value.unwrap().as_str(), "Hello, World!"); /// ``` -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] pub struct OnceLock<T> { once: Once, // Whether or not the value is initialized is tracked by `once.is_completed()`. @@ -40,8 +38,6 @@ pub struct OnceLock<T> { /// `PhantomData` to make sure dropck understands we're dropping T in our Drop impl. /// /// ```compile_fail,E0597 - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// struct A<'a>(&'a str); @@ -63,7 +59,8 @@ impl<T> OnceLock<T> { /// Creates a new empty cell. #[inline] #[must_use] - #[unstable(feature = "once_cell", issue = "74465")] + #[stable(feature = "once_cell", since = "1.70.0")] + #[rustc_const_stable(feature = "once_cell", since = "1.70.0")] pub const fn new() -> OnceLock<T> { OnceLock { once: Once::new(), @@ -77,7 +74,7 @@ impl<T> OnceLock<T> { /// Returns `None` if the cell is empty, or being initialized. This /// method never blocks. #[inline] - #[unstable(feature = "once_cell", issue = "74465")] + #[stable(feature = "once_cell", since = "1.70.0")] pub fn get(&self) -> Option<&T> { if self.is_initialized() { // Safe b/c checked is_initialized @@ -91,7 +88,7 @@ impl<T> OnceLock<T> { /// /// Returns `None` if the cell is empty. This method never blocks. #[inline] - #[unstable(feature = "once_cell", issue = "74465")] + #[stable(feature = "once_cell", since = "1.70.0")] pub fn get_mut(&mut self) -> Option<&mut T> { if self.is_initialized() { // Safe b/c checked is_initialized and we have a unique access @@ -111,8 +108,6 @@ impl<T> OnceLock<T> { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// static CELL: OnceLock<i32> = OnceLock::new(); @@ -129,7 +124,7 @@ impl<T> OnceLock<T> { /// } /// ``` #[inline] - #[unstable(feature = "once_cell", issue = "74465")] + #[stable(feature = "once_cell", since = "1.70.0")] pub fn set(&self, value: T) -> Result<(), T> { let mut value = Some(value); self.get_or_init(|| value.take().unwrap()); @@ -158,8 +153,6 @@ impl<T> OnceLock<T> { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// let cell = OnceLock::new(); @@ -169,7 +162,7 @@ impl<T> OnceLock<T> { /// assert_eq!(value, &92); /// ``` #[inline] - #[unstable(feature = "once_cell", issue = "74465")] + #[stable(feature = "once_cell", since = "1.70.0")] pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T, @@ -195,7 +188,7 @@ impl<T> OnceLock<T> { /// # Examples /// /// ``` - /// #![feature(once_cell)] + /// #![feature(once_cell_try)] /// /// use std::sync::OnceLock; /// @@ -209,7 +202,7 @@ impl<T> OnceLock<T> { /// assert_eq!(cell.get(), Some(&92)) /// ``` #[inline] - #[unstable(feature = "once_cell", issue = "74465")] + #[unstable(feature = "once_cell_try", issue = "109737")] pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>, @@ -236,8 +229,6 @@ impl<T> OnceLock<T> { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// let cell: OnceLock<String> = OnceLock::new(); @@ -248,7 +239,7 @@ impl<T> OnceLock<T> { /// assert_eq!(cell.into_inner(), Some("hello".to_string())); /// ``` #[inline] - #[unstable(feature = "once_cell", issue = "74465")] + #[stable(feature = "once_cell", since = "1.70.0")] pub fn into_inner(mut self) -> Option<T> { self.take() } @@ -262,8 +253,6 @@ impl<T> OnceLock<T> { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// let mut cell: OnceLock<String> = OnceLock::new(); @@ -275,7 +264,7 @@ impl<T> OnceLock<T> { /// assert_eq!(cell.get(), None); /// ``` #[inline] - #[unstable(feature = "once_cell", issue = "74465")] + #[stable(feature = "once_cell", since = "1.70.0")] pub fn take(&mut self) -> Option<T> { if self.is_initialized() { self.once = Once::new(); @@ -344,17 +333,17 @@ impl<T> OnceLock<T> { // scoped thread B, which fills the cell, which is // then destroyed by A. That is, destructor observes // a sent value. -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] unsafe impl<T: Sync + Send> Sync for OnceLock<T> {} -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] unsafe impl<T: Send> Send for OnceLock<T> {} -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T> {} -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] impl<T: UnwindSafe> UnwindSafe for OnceLock<T> {} -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] impl<T> const Default for OnceLock<T> { /// Creates a new empty cell. @@ -362,8 +351,6 @@ impl<T> const Default for OnceLock<T> { /// # Example /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// fn main() { @@ -376,7 +363,7 @@ impl<T> const Default for OnceLock<T> { } } -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] impl<T: fmt::Debug> fmt::Debug for OnceLock<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.get() { @@ -386,7 +373,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceLock<T> { } } -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] impl<T: Clone> Clone for OnceLock<T> { #[inline] fn clone(&self) -> OnceLock<T> { @@ -401,15 +388,13 @@ impl<T: Clone> Clone for OnceLock<T> { } } -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] impl<T> From<T> for OnceLock<T> { /// Create a new cell with its contents set to `value`. /// /// # Example /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// # fn main() -> Result<(), i32> { @@ -430,7 +415,7 @@ impl<T> From<T> for OnceLock<T> { } } -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] impl<T: PartialEq> PartialEq for OnceLock<T> { #[inline] fn eq(&self, other: &OnceLock<T>) -> bool { @@ -438,10 +423,10 @@ impl<T: PartialEq> PartialEq for OnceLock<T> { } } -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] impl<T: Eq> Eq for OnceLock<T> {} -#[unstable(feature = "once_cell", issue = "74465")] +#[stable(feature = "once_cell", since = "1.70.0")] unsafe impl<#[may_dangle] T> Drop for OnceLock<T> { #[inline] fn drop(&mut self) { |