diff options
| author | David Ross <daboross@daboross.net> | 2024-10-21 20:05:55 -0700 |
|---|---|---|
| committer | David Ross <daboross@daboross.net> | 2024-10-21 20:15:04 -0700 |
| commit | c18bab3fe64c8786c26ac483dac13f615e544276 (patch) | |
| tree | 85809e6d80c15bd06de018a863a51a14600a7de6 /library/std/src/sync | |
| parent | 814df6e50eaf89b90793e7d9618bb60f1f18377a (diff) | |
| download | rust-c18bab3fe64c8786c26ac483dac13f615e544276.tar.gz rust-c18bab3fe64c8786c26ac483dac13f615e544276.zip | |
Document PartialEq impl for OnceLock
Diffstat (limited to 'library/std/src/sync')
| -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() |
