diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs index 7ce25cb..ad2905d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -165,6 +165,24 @@ impl<'a, T: ?Sized> ConstLtPtr<'a, T> { pub const unsafe fn as_raw(&self) -> *const T { self.raw } + + /// Checks if this pointer is null. + /// + /// # Examples + /// + /// A null pointer is null: + /// + /// ```rust + /// use ltptr::ConstLtPtr; + /// + /// let raw_ptr = core::ptr::null::<()>(); + /// let lt_ptr = unsafe { ConstLtPtr::from_raw(raw_ptr) }; + /// assert!(lt_ptr.is_null()); + /// ``` + #[inline] + pub fn is_null(self) -> bool { + self.raw.is_null() + } } impl<'a, T: ?Sized> MutLtPtr<'a, T> { @@ -193,4 +211,21 @@ impl<'a, T: ?Sized> MutLtPtr<'a, T> { pub const unsafe fn as_raw(&self) -> *mut T { self.raw } + + /// Checks if this pointer is null. + /// # Examples + /// + /// A null pointer is null: + /// + /// ```rust + /// use ltptr::MutLtPtr; + /// + /// let raw_ptr = core::ptr::null_mut::<()>(); + /// let lt_ptr = unsafe { MutLtPtr::from_raw(raw_ptr) }; + /// assert!(lt_ptr.is_null()); + /// ``` + #[inline] + pub fn is_null(self) -> bool { + self.raw.is_null() + } } |