diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-11 15:42:58 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-13 17:18:24 -0400 |
| commit | 6c4843d9da70aeb402fc788e07e7912ecbee3559 (patch) | |
| tree | bf9b52f93e36ba30e54cf5863b17dbe119c0d630 /src | |
| parent | 3dbce4ebea8b36c873b1b29e5a56d5a8b86feee6 (diff) | |
Add ptr::ref_eq()
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/ptr.rs | 10 |
1 files 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 memcpy; 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(); -} \ No newline at end of file +} |
