diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-26 18:45:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-26 18:45:33 +0200 |
| commit | 1f6cb859ee79b3f32eca5c87af87e9bc0aa4daa3 (patch) | |
| tree | dd80c234a339ea0c73a53af706fc9c32f7fe58e4 | |
| parent | 13ec1b0c979938cdf23aa7f69f65e57ca043e74d (diff) | |
| parent | c18bab3fe64c8786c26ac483dac13f615e544276 (diff) | |
| download | rust-1f6cb859ee79b3f32eca5c87af87e9bc0aa4daa3.tar.gz rust-1f6cb859ee79b3f32eca5c87af87e9bc0aa4daa3.zip | |
Rollup merge of #132019 - daboross:document-partialeq-oncelock, r=Mark-Simulacrum
Document `PartialEq` impl for `OnceLock` Adds documentation to `std::sync::OnceLock`'s `PartialEq` implementation: specifies publicly that `OnceLock`s are compared based on their contents, and nothing else. Created in response to, but not directly related to, https://github.com/rust-lang/rust/issues/131959. ## ne This doesn't create and document `PartialEq::ne`. There's precedent for this in [`RefCell`](https://doc.rust-lang.org/std/cell/struct.RefCell.html#impl-PartialEq-for-RefCell%3CT%3E).
| -rw-r--r-- | library/std/src/sync/once_lock.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index be615a5a8ef..0ae3cf4df36 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -634,6 +634,26 @@ impl<T> From<T> for OnceLock<T> { #[stable(feature = "once_cell", since = "1.70.0")] 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] fn eq(&self, other: &OnceLock<T>) -> bool { self.get() == other.get() |
