summaryrefslogtreecommitdiffstats
path: root/vendor/once_cell/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:11:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:13:23 +0000
commit20431706a863f92cb37dc512fef6e48d192aaf2c (patch)
tree2867f13f5fd5437ba628c67d7f87309ccadcd286 /vendor/once_cell/src/lib.rs
parentReleasing progress-linux version 1.65.0+dfsg1-2~progress7.99u1. (diff)
downloadrustc-20431706a863f92cb37dc512fef6e48d192aaf2c.tar.xz
rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.zip
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/once_cell/src/lib.rs')
-rw-r--r--vendor/once_cell/src/lib.rs80
1 files changed, 72 insertions, 8 deletions
diff --git a/vendor/once_cell/src/lib.rs b/vendor/once_cell/src/lib.rs
index 70f08dea6..6de1e3eeb 100644
--- a/vendor/once_cell/src/lib.rs
+++ b/vendor/once_cell/src/lib.rs
@@ -267,7 +267,7 @@
//!
//! # Minimum Supported `rustc` Version
//!
-//! This crate's minimum supported `rustc` version is `1.36.0`.
+//! This crate's minimum supported `rustc` version is `1.56.0`.
//!
//! If only the `std` feature is enabled, MSRV will be updated conservatively.
//! When using other features, like `parking_lot`, MSRV might be updated more frequently, up to the latest stable.
@@ -348,11 +348,9 @@ pub mod unsync {
cell::{Cell, UnsafeCell},
fmt, hint, mem,
ops::{Deref, DerefMut},
+ panic::{RefUnwindSafe, UnwindSafe},
};
- #[cfg(feature = "std")]
- use std::panic::{RefUnwindSafe, UnwindSafe};
-
/// A cell which can be written to only once. It is not thread safe.
///
/// Unlike [`std::cell::RefCell`], a `OnceCell` provides simple `&`
@@ -382,9 +380,7 @@ pub mod unsync {
// `&unsync::OnceCell` to sneak a `T` through `catch_unwind`,
// by initializing the cell in closure and extracting the value in the
// `Drop`.
- #[cfg(feature = "std")]
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceCell<T> {}
- #[cfg(feature = "std")]
impl<T: UnwindSafe> UnwindSafe for OnceCell<T> {}
impl<T> Default for OnceCell<T> {
@@ -680,7 +676,6 @@ pub mod unsync {
init: Cell<Option<F>>,
}
- #[cfg(feature = "std")]
impl<T, F: RefUnwindSafe> RefUnwindSafe for Lazy<T, F> where OnceCell<T>: RefUnwindSafe {}
impl<T: fmt::Debug, F> fmt::Debug for Lazy<T, F> {
@@ -742,6 +737,25 @@ pub mod unsync {
})
}
+ /// Forces the evaluation of this lazy value and returns a mutable reference to
+ /// the result.
+ ///
+ /// This is equivalent to the `DerefMut` impl, but is explicit.
+ ///
+ /// # Example
+ /// ```
+ /// use once_cell::unsync::Lazy;
+ ///
+ /// let mut lazy = Lazy::new(|| 92);
+ ///
+ /// assert_eq!(Lazy::force_mut(&mut lazy), &92);
+ /// assert_eq!(*lazy, 92);
+ /// ```
+ pub fn force_mut(this: &mut Lazy<T, F>) -> &mut T {
+ Self::force(this);
+ Self::get_mut(this).unwrap_or_else(|| unreachable!())
+ }
+
/// Gets the reference to the result of this lazy value if
/// it was initialized, otherwise returns `None`.
///
@@ -758,6 +772,23 @@ pub mod unsync {
pub fn get(this: &Lazy<T, F>) -> Option<&T> {
this.cell.get()
}
+
+ /// Gets the mutable reference to the result of this lazy value if
+ /// it was initialized, otherwise returns `None`.
+ ///
+ /// # Example
+ /// ```
+ /// use once_cell::unsync::Lazy;
+ ///
+ /// let mut lazy = Lazy::new(|| 92);
+ ///
+ /// assert_eq!(Lazy::get_mut(&mut lazy), None);
+ /// assert_eq!(*lazy, 92);
+ /// assert_eq!(Lazy::get_mut(&mut lazy), Some(&mut 92));
+ /// ```
+ pub fn get_mut(this: &mut Lazy<T, F>) -> Option<&mut T> {
+ this.cell.get_mut()
+ }
}
impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
@@ -1189,7 +1220,6 @@ pub mod sync {
unsafe impl<T, F: Send> Sync for Lazy<T, F> where OnceCell<T>: Sync {}
// auto-derived `Send` impl is OK.
- #[cfg(feature = "std")]
impl<T, F: RefUnwindSafe> RefUnwindSafe for Lazy<T, F> where OnceCell<T>: RefUnwindSafe {}
impl<T, F> Lazy<T, F> {
@@ -1232,6 +1262,23 @@ pub mod sync {
})
}
+ /// Forces the evaluation of this lazy value and
+ /// returns a mutable reference to the result. This is equivalent
+ /// to the `Deref` impl, but is explicit.
+ ///
+ /// # Example
+ /// ```
+ /// use once_cell::sync::Lazy;
+ ///
+ /// let mut lazy = Lazy::new(|| 92);
+ ///
+ /// assert_eq!(Lazy::force_mut(&mut lazy), &mut 92);
+ /// ```
+ pub fn force_mut(this: &mut Lazy<T, F>) -> &mut T {
+ Self::force(this);
+ Self::get_mut(this).unwrap_or_else(|| unreachable!())
+ }
+
/// Gets the reference to the result of this lazy value if
/// it was initialized, otherwise returns `None`.
///
@@ -1248,6 +1295,23 @@ pub mod sync {
pub fn get(this: &Lazy<T, F>) -> Option<&T> {
this.cell.get()
}
+
+ /// Gets the reference to the result of this lazy value if
+ /// it was initialized, otherwise returns `None`.
+ ///
+ /// # Example
+ /// ```
+ /// use once_cell::sync::Lazy;
+ ///
+ /// let mut lazy = Lazy::new(|| 92);
+ ///
+ /// assert_eq!(Lazy::get_mut(&mut lazy), None);
+ /// assert_eq!(&*lazy, &92);
+ /// assert_eq!(Lazy::get_mut(&mut lazy), Some(&mut 92));
+ /// ```
+ pub fn get_mut(this: &mut Lazy<T, F>) -> Option<&mut T> {
+ this.cell.get_mut()
+ }
}
impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {