core: Add extension methods for is_null, is_not_null
This commit is contained in:
@@ -8,6 +8,7 @@ import path = path::path;
|
|||||||
import str::extensions;
|
import str::extensions;
|
||||||
import vec::extensions;
|
import vec::extensions;
|
||||||
import option::extensions;
|
import option::extensions;
|
||||||
|
import ptr::extensions;
|
||||||
|
|
||||||
export path, option, some, none, unreachable;
|
export path, option, some, none, unreachable;
|
||||||
export extensions;
|
export extensions;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export memcpy;
|
|||||||
export memmove;
|
export memmove;
|
||||||
export buf_len;
|
export buf_len;
|
||||||
export position;
|
export position;
|
||||||
|
export extensions;
|
||||||
|
|
||||||
import libc::c_void;
|
import libc::c_void;
|
||||||
|
|
||||||
@@ -100,6 +101,15 @@ unsafe fn memmove<T>(dst: *T, src: *T, count: uint) {
|
|||||||
libc_::memmove(dst as *c_void, src as *c_void, n);
|
libc_::memmove(dst as *c_void, src as *c_void, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Extension methods for pointers"]
|
||||||
|
impl extensions<T> for *T {
|
||||||
|
#[doc = "Returns true if the pointer is equal to the null pointer."]
|
||||||
|
pure fn is_null<T>() -> bool { is_null(self) }
|
||||||
|
|
||||||
|
#[doc = "Returns true if the pointer is not equal to the null pointer."]
|
||||||
|
pure fn is_not_null<T>() -> bool { is_not_null(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test() unsafe {
|
fn test() unsafe {
|
||||||
type pair = {mut fst: int, mut snd: int};
|
type pair = {mut fst: int, mut snd: int};
|
||||||
|
|||||||
Reference in New Issue
Block a user