Skip to content

Commit

Permalink
Document PartialEq impl for OnceLock
Browse files Browse the repository at this point in the history
  • Loading branch information
daboross committed Oct 22, 2024
1 parent 2e8dd5b commit 61fa53e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions std/src/sync/once_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 61fa53e

Please sign in to comment.