Skip to content

Commit

Permalink
refactor: unsafe pointer dereference to include explicit null check
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Apr 25, 2024
1 parent c928d9d commit 9625c1b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<T> Deref for OwnedRef<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
unsafe { &*self.value }
unsafe { self.value.as_ref().unwrap() }
}
}

Expand All @@ -153,14 +153,14 @@ impl<T> Deref for OwnedRefMut<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
unsafe { &*self.value }
unsafe { self.value.as_ref().unwrap() }
}
}

/// Implements `DerefMut` for `OwnedRefMut` to allow dereferencing the owned mutable reference.
impl<T> DerefMut for OwnedRefMut<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.value }
unsafe { self.value.as_mut().unwrap() }
}
}

Expand Down

0 comments on commit 9625c1b

Please sign in to comment.