Add ptr::ref_eq()

This commit is contained in:
Ben Blum 2012-08-11 15:42:58 -04:00
parent 3dbce4ebea
commit 6c4843d9da

View File

@ -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<T>(thing: &T) -> uint unsafe {
unsafe::reinterpret_cast(thing)
}
/// Determine if two borrowed pointers point to the same thing.
#[inline(always)]
fn ref_eq<T>(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();
}
}