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).
This commit is contained in:
commit
1f6cb859ee
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user