Skip to content

Commit cbc76a2

Browse files
authored
Merge pull request #557 from wedsonaf/raw-mut-pointer-wrapper
rust: add `PointerWrapper` implementation for `*mut T`.
2 parents 3cc55c1 + 21a85a1 commit cbc76a2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

rust/kernel/types.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ impl<T: PointerWrapper + Deref> PointerWrapper for Pin<T> {
128128
}
129129
}
130130

131+
impl<T> PointerWrapper for *mut T {
132+
type Borrowed<'a> = *mut T;
133+
134+
fn into_pointer(self) -> *const c_types::c_void {
135+
self as _
136+
}
137+
138+
unsafe fn borrow<'a>(ptr: *const c_types::c_void) -> Self::Borrowed<'a> {
139+
ptr as _
140+
}
141+
142+
unsafe fn from_pointer(ptr: *const c_types::c_void) -> Self {
143+
ptr as _
144+
}
145+
}
146+
131147
/// Runs a cleanup function/closure when dropped.
132148
///
133149
/// The [`ScopeGuard::dismiss`] function prevents the cleanup function from running.

0 commit comments

Comments
 (0)