pub unsafe trait Boxable: Sized {
type OtType: Sized;
// Required method
unsafe fn finalize(&mut self);
// Provided methods
unsafe fn ref_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a Self> { ... }
unsafe fn ref_from_ot_const_ptr<'a>(
ptr: *const Self::OtType,
) -> Option<&'a Self> { ... }
unsafe fn mut_from_ot_ptr<'a>(
ptr: *mut Self::OtType,
) -> Option<&'a mut Self> { ... }
fn as_ot_ptr(&self) -> *mut Self::OtType { ... }
}
Expand description
Trait for OpenThread Rust types for which an owned opaque instance is kept in a [ot::Box<>
].
§Safety
The safety of implementing this trait is dependent on the following assumptions:
- The type
Self
is never instantiated or passed by value. It must only ever used by reference (&Self
or&mut Self
). - No member of
Self
is ever accessed directly or exposed publicly.
Because of the above restrictions, Self
is usually a zero-sized type.
Required Associated Types§
Required Methods§
Sourceunsafe fn finalize(&mut self)
unsafe fn finalize(&mut self)
Finalizes or frees the underlying OpenThread object.
This method should only be called by the Drop::drop
method on ot::Box
.
It should not be called directly. This is usually the only method that
needs to be implemented from this trait: the default implementations of
the other methods is sufficient.
§Safety
This method is considered unsafe to call directly because it invalidates
the underlying OpenThread object. This method should only ever be called
from a single place: Drop::drop()
on ot::Box
.
Provided Methods§
Sourceunsafe fn ref_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a Self>
unsafe fn ref_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a Self>
Creates a reference to a safe wrapper object from an OpenThread pointer.
§Safety
This method is unsafe because it allows you to cast an arbitrary pointer to a reference. When calling, care must be taken to ensure the following is true:
- The given pointer points to a valid instance of
Self::OtType
for the given lifetime.
Sourceunsafe fn ref_from_ot_const_ptr<'a>(
ptr: *const Self::OtType,
) -> Option<&'a Self>
unsafe fn ref_from_ot_const_ptr<'a>( ptr: *const Self::OtType, ) -> Option<&'a Self>
Creates a reference to a safe wrapper object from an OpenThread const pointer.
§Safety
This method is unsafe because it allows you to cast an arbitrary pointer to a reference. When calling, care must be taken to ensure the following is true:
- The given pointer points to a valid instance of
Self::OtType
for the given lifetime.
Sourceunsafe fn mut_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a mut Self>
unsafe fn mut_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a mut Self>
Creates a mutable reference to a safe wrapper object from an OpenThread pointer.
§Safety
This method is unsafe because it allows you to cast an arbitrary pointer to a reference. When calling, care must be taken to ensure the following is true:
- The given pointer points to a valid instance of
Self::OtType
. - The given pointer is not
NULL
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.