Skip to content

Commit 7a2d7aa

Browse files
committed
core: Add extension methods for is_null, is_not_null
1 parent 0f65872 commit 7a2d7aa

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/libcore/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import path = path::path;
88
import str::extensions;
99
import vec::extensions;
1010
import option::extensions;
11+
import ptr::extensions;
1112

1213
export path, option, some, none, unreachable;
1314
export extensions;

src/libcore/ptr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export memcpy;
1111
export memmove;
1212
export buf_len;
1313
export position;
14+
export extensions;
1415

1516
import libc::c_void;
1617

@@ -100,6 +101,15 @@ unsafe fn memmove<T>(dst: *T, src: *T, count: uint) {
100101
libc_::memmove(dst as *c_void, src as *c_void, n);
101102
}
102103

104+
#[doc = "Extension methods for pointers"]
105+
impl extensions<T> for *T {
106+
#[doc = "Returns true if the pointer is equal to the null pointer."]
107+
pure fn is_null<T>() -> bool { is_null(self) }
108+
109+
#[doc = "Returns true if the pointer is not equal to the null pointer."]
110+
pure fn is_not_null<T>() -> bool { is_not_null(self) }
111+
}
112+
103113
#[test]
104114
fn test() unsafe {
105115
type pair = {mut fst: int, mut snd: int};

0 commit comments

Comments
 (0)