@@ -634,6 +634,26 @@ impl From for OnceLock { |
|
|
634 |
634 |
|
635 |
635 |
#[stable(feature = "once_cell", since = "1.70.0")] |
636 |
636 |
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::::new() == OnceLock::::new()); |
|
656 |
+ /// ``` |
637 |
657 |
#[inline] |
638 |
658 |
fn eq(&self, other: &OnceLock<T>) -> bool { |
639 |
659 |
self.get() == other.get() |