Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3949f2f

Browse files
authored
Unrolled build for rust-lang#132019
Rollup merge of rust-lang#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, rust-lang#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).
2 parents 4d88de2 + c18bab3 commit 3949f2f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/std/src/sync/once_lock.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,26 @@ impl<T> From<T> for OnceLock<T> {
634634

635635
#[stable(feature = "once_cell", since = "1.70.0")]
636636
impl<T: PartialEq> PartialEq for OnceLock<T> {
637+
/// Equality for two `OnceLock`s.
638+
///
639+
/// Two `OnceLock`s are equal if they either both contain values and their
640+
/// values are equal, or if neither contains a value.
641+
///
642+
/// # Examples
643+
///
644+
/// ```
645+
/// use std::sync::OnceLock;
646+
///
647+
/// let five = OnceLock::new();
648+
/// five.set(5).unwrap();
649+
///
650+
/// let also_five = OnceLock::new();
651+
/// also_five.set(5).unwrap();
652+
///
653+
/// assert!(five == also_five);
654+
///
655+
/// assert!(OnceLock::<u32>::new() == OnceLock::<u32>::new());
656+
/// ```
637657
#[inline]
638658
fn eq(&self, other: &OnceLock<T>) -> bool {
639659
self.get() == other.get()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy