Skip to content

Commit 104fa4f

Browse files
committed
rust: implement PointerWrapper for unit type.
This is useful for cases when we don't need to store any information as context. Implementing `PointerWrapper` for `()` allows us to directly use it as the context type. Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 4349c44 commit 104fa4f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

rust/kernel/types.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ impl<T> PointerWrapper for *mut T {
144144
}
145145
}
146146

147+
impl PointerWrapper for () {
148+
type Borrowed<'a> = ();
149+
150+
fn into_pointer(self) -> *const c_types::c_void {
151+
// We use 1 to be different from a null pointer.
152+
1usize as _
153+
}
154+
155+
unsafe fn borrow<'a>(_: *const c_types::c_void) -> Self::Borrowed<'a> {}
156+
157+
unsafe fn from_pointer(_: *const c_types::c_void) -> Self {}
158+
}
159+
147160
/// Runs a cleanup function/closure when dropped.
148161
///
149162
/// The [`ScopeGuard::dismiss`] function prevents the cleanup function from running.

0 commit comments

Comments
 (0)