summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-12-07 07:54:29 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-12-07 07:54:39 -0300
commit6ecb7cd29ffe756cc80c81510fcb0e902dc99f9c (patch)
tree82f892ae89610ceb97badb268ef5b36c59ccc00e
parent0cbd0b9b701c4d067b8dd0fdccc0ebe5c6b6e7e1 (diff)
Add is_null and release 0.1.5 HEAD default
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs35
2 files changed, 36 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 5165718..8da9914 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "ltptr"
-version = "0.1.4"
+version = "0.1.5"
 edition = "2021"
 license = "0BSD"
 description = "Checked raw pointers."
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()
+    }
 }