mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 01:42:54 +03:00
Add sync::Weak::ptr_eq
This commit is contained in:
@@ -1130,6 +1130,53 @@ fn inner(&self) -> Option<&ArcInner<T>> {
|
||||
Some(unsafe { self.ptr.as_ref() })
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the two `Weak`s point to the same value (not just values
|
||||
/// that compare as equal).
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// Since this compares pointers it means that `Weak::new()` will equal each
|
||||
/// other, even though they don't point to any value.
|
||||
///
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(weak_ptr_eq)]
|
||||
/// use std::sync::{Arc, Weak};
|
||||
///
|
||||
/// let first_rc = Arc::new(5);
|
||||
/// let first = Arc::downgrade(&first_rc);
|
||||
/// let second = Arc::downgrade(&first_rc);
|
||||
///
|
||||
/// assert!(Weak::ptr_eq(&first, &second));
|
||||
///
|
||||
/// let third_rc = Arc::new(5);
|
||||
/// let third = Arc::downgrade(&third_rc);
|
||||
///
|
||||
/// assert!(!Weak::ptr_eq(&first, &third));
|
||||
/// ```
|
||||
///
|
||||
/// Comparing `Weak::new`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(weak_ptr_eq)]
|
||||
/// use std::sync::{Arc, Weak};
|
||||
///
|
||||
/// let first = Weak::new();
|
||||
/// let second = Weak::new();
|
||||
/// assert!(Weak::ptr_eq(&first, &second));
|
||||
///
|
||||
/// let third_rc = Arc::new(());
|
||||
/// let third = Arc::downgrade(&third_rc);
|
||||
/// assert!(!Weak::ptr_eq(&first, &third));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "weak_ptr_eq", issue = "55981")]
|
||||
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
|
||||
this.ptr.as_ptr() == other.ptr.as_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "arc_weak", since = "1.4.0")]
|
||||
|
||||
Reference in New Issue
Block a user