From 6ecb7cd29ffe756cc80c81510fcb0e902dc99f9c Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 7 Dec 2024 07:54:29 -0300 Subject: Add is_null and release 0.1.5 --- src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src') 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() + } } -- cgit 1.4.1