summary refs log tree commit diff
path: root/src/libcore/box.rs
blob: 114c495d64d9464421e949cdb1f56addbdba2dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export ptr_eq;

#[doc(
  brief = "Determine if two shared boxes point to the same object"
)]
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
    // FIXME: ptr::addr_of
    unsafe {
        let a_ptr: uint = unsafe::reinterpret_cast(a);
        let b_ptr: uint = unsafe::reinterpret_cast(b);
        ret a_ptr == b_ptr;
    }
}

#[test]
fn test() {
    let x = @3;
    let y = @3;
    assert (ptr_eq::<int>(x, x));
    assert (ptr_eq::<int>(y, y));
    assert (!ptr_eq::<int>(x, y));
    assert (!ptr_eq::<int>(y, x));
}