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