Document PartialEq impl for OnceLock

This commit is contained in:
David Ross 2024-10-21 20:05:55 -07:00
parent 814df6e50e
commit c18bab3fe6

View File

@ -634,6 +634,26 @@ impl<T> From<T> for OnceLock<T> {
#[stable(feature = "once_cell", since = "1.70.0")] #[stable(feature = "once_cell", since = "1.70.0")]
impl<T: PartialEq> PartialEq for OnceLock<T> { impl<T: PartialEq> PartialEq for OnceLock<T> {
/// Equality for two `OnceLock`s.
///
/// Two `OnceLock`s are equal if they either both contain values and their
/// values are equal, or if neither contains a value.
///
/// # Examples
///
/// ```
/// use std::sync::OnceLock;
///
/// let five = OnceLock::new();
/// five.set(5).unwrap();
///
/// let also_five = OnceLock::new();
/// also_five.set(5).unwrap();
///
/// assert!(five == also_five);
///
/// assert!(OnceLock::<u32>::new() == OnceLock::<u32>::new());
/// ```
#[inline] #[inline]
fn eq(&self, other: &OnceLock<T>) -> bool { fn eq(&self, other: &OnceLock<T>) -> bool {
self.get() == other.get() self.get() == other.get()