Skip to content

Commit

Permalink
Merge pull request torvalds#557 from wedsonaf/raw-mut-pointer-wrapper
Browse files Browse the repository at this point in the history
rust: add `PointerWrapper` implementation for `*mut T`.
  • Loading branch information
ojeda authored Nov 17, 2021
2 parents 3cc55c1 + 21a85a1 commit cbc76a2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rust/kernel/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ impl<T: PointerWrapper + Deref> PointerWrapper for Pin<T> {
}
}

impl<T> PointerWrapper for *mut T {
type Borrowed<'a> = *mut T;

fn into_pointer(self) -> *const c_types::c_void {
self as _
}

unsafe fn borrow<'a>(ptr: *const c_types::c_void) -> Self::Borrowed<'a> {
ptr as _
}

unsafe fn from_pointer(ptr: *const c_types::c_void) -> Self {
ptr as _
}
}

/// Runs a cleanup function/closure when dropped.
///
/// The [`ScopeGuard::dismiss`] function prevents the cleanup function from running.
Expand Down

0 comments on commit cbc76a2

Please sign in to comment.