Skip to content

Commit a3fb8b8

Browse files
authored
Merge pull request torvalds#584 from wedsonaf/unit-pointer-wrapper
rust: implement `PointerWrapper` for unit type.
2 parents f164109 + 104fa4f commit a3fb8b8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

rust/kernel/types.rs

+13
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)