@@ -1187,8 +1187,9 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Weak<U>> for Weak<T> {}
1187
1187
1188
1188
impl < T > Weak < T > {
1189
1189
/// Constructs a new `Weak<T>`, without allocating any memory.
1190
- /// Calling [`upgrade`][Weak::upgrade] on the return value always gives [`None`].
1190
+ /// Calling [`upgrade`] on the return value always gives [`None`].
1191
1191
///
1192
+ /// [`upgrade`]: #method.upgrade
1192
1193
/// [`None`]: ../../std/option/enum.Option.html
1193
1194
///
1194
1195
/// # Examples
@@ -1260,6 +1261,52 @@ impl<T: ?Sized> Weak<T> {
1260
1261
Some ( unsafe { self . ptr . as_ref ( ) } )
1261
1262
}
1262
1263
}
1264
+
1265
+ /// Returns true if the two `Weak`s point to the same value (not just values
1266
+ /// that compare as equal).
1267
+ ///
1268
+ /// # Notes
1269
+ ///
1270
+ /// Since this compares pointers it means that `Weak::new()` will equal each
1271
+ /// other, even though they don't point to any value.
1272
+ ///
1273
+ /// # Examples
1274
+ ///
1275
+ /// ```
1276
+ /// #![feature(weak_ptr_eq)]
1277
+ /// use std::rc::{Rc, Weak};
1278
+ ///
1279
+ /// let first_rc = Rc::new(5);
1280
+ /// let first = Rc::downgrade(&first_rc);
1281
+ /// let second = Rc::downgrade(&first_rc);
1282
+ ///
1283
+ /// assert!(Weak::ptr_eq(&first, &second));
1284
+ ///
1285
+ /// let third_rc = Rc::new(5);
1286
+ /// let third = Rc::downgrade(&third_rc);
1287
+ ///
1288
+ /// assert!(!Weak::ptr_eq(&first, &third));
1289
+ /// ```
1290
+ ///
1291
+ /// Comparing `Weak::new`.
1292
+ ///
1293
+ /// ```
1294
+ /// #![feature(weak_ptr_eq)]
1295
+ /// use std::rc::{Rc, Weak};
1296
+ ///
1297
+ /// let first = Weak::new();
1298
+ /// let second = Weak::new();
1299
+ /// assert!(Weak::ptr_eq(&first, &second));
1300
+ ///
1301
+ /// let third_rc = Rc::new(());
1302
+ /// let third = Rc::downgrade(&third_rc);
1303
+ /// assert!(!Weak::ptr_eq(&first, &third));
1304
+ /// ```
1305
+ #[ inline]
1306
+ #[ unstable( feature = "weak_ptr_eq" , issue = "55981" ) ]
1307
+ pub fn ptr_eq ( this : & Self , other : & Self ) -> bool {
1308
+ this. ptr . as_ptr ( ) == other. ptr . as_ptr ( )
1309
+ }
1263
1310
}
1264
1311
1265
1312
#[ stable( feature = "rc_weak" , since = "1.4.0" ) ]
0 commit comments