Skip to content

Commit 3b8097d

Browse files
committed
core: Add ptr::is_null/is_not_null
1 parent e325146 commit 3b8097d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libcore/ptr.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
4949

5050
#[doc = "Create an unsafe null pointer"]
5151
#[inline(always)]
52-
fn null<T>() -> *T unsafe { ret unsafe::reinterpret_cast(0u); }
52+
pure fn null<T>() -> *T unsafe { ret unsafe::reinterpret_cast(0u); }
53+
54+
#[doc = "Returns true if the pointer is equal to the null pointer"]
55+
pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
56+
57+
#[doc = "Returns true if the pointer is not equal to the null pointer"]
58+
pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
5359

5460
#[doc = "
5561
Copies data from one location to another

0 commit comments

Comments
 (0)