summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-04-15 21:46:29 -0700
committerBrian Anderson <banderson@mozilla.com>2012-04-15 21:46:29 -0700
commit7a2d7aa5dee7832a9afc9ba18c8ffc3622e3c00c (patch)
treed1886afb17b1697b98c520df15b3d6ce5f35fb08 /src/libcore
parent0f65872438bf7a797094ef358e37c0b32c210bd8 (diff)
downloadrust-7a2d7aa5dee7832a9afc9ba18c8ffc3622e3c00c.tar.gz
rust-7a2d7aa5dee7832a9afc9ba18c8ffc3622e3c00c.zip
core: Add extension methods for is_null, is_not_null
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/core.rs1
-rw-r--r--src/libcore/ptr.rs10
2 files changed, 11 insertions, 0 deletions
diff --git a/src/libcore/core.rs b/src/libcore/core.rs
index 39781df0ef0..d359cbf083d 100644
--- a/src/libcore/core.rs
+++ b/src/libcore/core.rs
@@ -8,6 +8,7 @@ import path = path::path;
 import str::extensions;
 import vec::extensions;
 import option::extensions;
+import ptr::extensions;
 
 export path, option, some, none, unreachable;
 export extensions;
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index be74dfad32e..7df8499e2b5 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -11,6 +11,7 @@ export memcpy;
 export memmove;
 export buf_len;
 export position;
+export extensions;
 
 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);
 }
 
+#[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]
 fn test() unsafe {
     type pair = {mut fst: int, mut snd: int};