From 6c4843d9da70aeb402fc788e07e7912ecbee3559 Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Sat, 11 Aug 2012 15:42:58 -0400 Subject: [PATCH] Add ptr::ref_eq() --- src/libcore/ptr.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 61990b745ad..c06f3f1d3a4 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -13,9 +13,9 @@ export memmove; export memset; export to_uint; +export ref_eq; export buf_len; export position; -export extensions; export ptr; import libc::{c_void, size_t}; @@ -150,6 +150,12 @@ fn to_uint(thing: &T) -> uint unsafe { unsafe::reinterpret_cast(thing) } +/// Determine if two borrowed pointers point to the same thing. +#[inline(always)] +fn ref_eq(thing: &T, other: &T) -> bool { + to_uint(thing) == to_uint(other) +} + trait ptr { pure fn is_null() -> bool; pure fn is_not_null() -> bool; @@ -236,4 +242,4 @@ fn test_is_null() { let q = ptr::offset(p, 1u); assert !q.is_null(); assert q.is_not_null(); -} \ No newline at end of file +}