Skip to content

Commit 61fa53e

Browse files
committed
Document PartialEq impl for OnceLock
1 parent 2e8dd5b commit 61fa53e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

std/src/sync/once_lock.rs

+20
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)