Skip to content

Commit 21a85a1

Browse files
committed
rust: add PointerWrapper implementation for *mut T.
The implementation is straightforward: converting to `void *` and borrowing are just pointer casts. This is used by the GPIO subsystem where some context data is controlled by the C side, so it is necessarily a raw pointer. (This is hidden from driver writers though.) Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 3cc55c1 commit 21a85a1

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)