mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
rust: types: implement ForeignOwnable
for the unit type
This allows us to use the unit type `()` when we have no object whose ownership must be managed but one implementing the `ForeignOwnable` trait is needed. Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
26949bac1e
commit
7118594466
@ -85,6 +85,18 @@ impl<T: 'static> ForeignOwnable for Box<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ForeignOwnable for () {
|
||||
type Borrowed<'a> = ();
|
||||
|
||||
fn into_foreign(self) -> *const core::ffi::c_void {
|
||||
core::ptr::NonNull::dangling().as_ptr()
|
||||
}
|
||||
|
||||
unsafe fn borrow<'a>(_: *const core::ffi::c_void) -> Self::Borrowed<'a> {}
|
||||
|
||||
unsafe fn from_foreign(_: *const core::ffi::c_void) -> Self {}
|
||||
}
|
||||
|
||||
/// Runs a cleanup function/closure when dropped.
|
||||
///
|
||||
/// The [`ScopeGuard::dismiss`] function prevents the cleanup function from running.
|
||||
|
Loading…
Reference in New Issue
Block a user