Skip to content

Commit 6c4843d

Browse files
committed
Add ptr::ref_eq()
1 parent 3dbce4e commit 6c4843d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libcore/ptr.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export memcpy;
1313
export memmove;
1414
export memset;
1515
export to_uint;
16+
export ref_eq;
1617
export buf_len;
1718
export position;
18-
export extensions;
1919
export ptr;
2020

2121
import libc::{c_void, size_t};
@@ -150,6 +150,12 @@ fn to_uint<T>(thing: &T) -> uint unsafe {
150150
unsafe::reinterpret_cast(thing)
151151
}
152152

153+
/// Determine if two borrowed pointers point to the same thing.
154+
#[inline(always)]
155+
fn ref_eq<T>(thing: &T, other: &T) -> bool {
156+
to_uint(thing) == to_uint(other)
157+
}
158+
153159
trait ptr {
154160
pure fn is_null() -> bool;
155161
pure fn is_not_null() -> bool;
@@ -236,4 +242,4 @@ fn test_is_null() {
236242
let q = ptr::offset(p, 1u);
237243
assert !q.is_null();
238244
assert q.is_not_null();
239-
}
245+
}

0 commit comments

Comments
 (0)