Skip to content

Commit

Permalink
pagebox: simplify some impls
Browse files Browse the repository at this point in the history
We can make use of the `Deref` and `DerefMut` implementations.

Signed-off-by: Tom Dohrmann <[email protected]>
  • Loading branch information
Freax13 committed Oct 25, 2024
1 parent 48e2e3e commit 9ec1021
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions kernel/src/mm/pagebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,36 +206,28 @@ impl<T: ?Sized> DerefMut for PageBox<T> {
impl<T: ?Sized> borrow::Borrow<T> for PageBox<T> {
#[inline]
fn borrow(&self) -> &T {
// SAFETY: this is part of the invariants of this type, as it must
// hold a pointer to valid memory for the given `T`.
unsafe { self.ptr.as_ref() }
self
}
}

impl<T: ?Sized> borrow::BorrowMut<T> for PageBox<T> {
#[inline]
fn borrow_mut(&mut self) -> &mut T {
// SAFETY: this is part of the invariants of this type, as it must
// hold a pointer to valid memory for the given `T`.
unsafe { self.ptr.as_mut() }
self
}
}

impl<T: ?Sized> AsRef<T> for PageBox<T> {
#[inline]
fn as_ref(&self) -> &T {
// SAFETY: this is part of the invariants of this type, as it must
// hold a pointer to valid memory for the given `T`.
unsafe { self.ptr.as_ref() }
self
}
}

impl<T: ?Sized> AsMut<T> for PageBox<T> {
#[inline]
fn as_mut(&mut self) -> &mut T {
// SAFETY: this is part of the invariants of this type, as it must
// hold a pointer to valid memory for the given `T`.
unsafe { self.ptr.as_mut() }
self
}
}

Expand Down

0 comments on commit 9ec1021

Please sign in to comment.