pub unsafe trait ItemEntry {
type Ref<'a>: Deref<Target = Self>
where Self: 'a;
// Required methods
fn into_raw(self) -> *const ();
unsafe fn from_raw(raw: *const ()) -> Self;
unsafe fn raw_as_ref<'a>(raw: *const ()) -> Self::Ref<'a>;
}
Expand description
A trait for the types users wish to store in an XArray
.
Items stored in an XArray
must be representable by a *const ()
aligned to 4. We prefer
*const ()
than usize
to make the implementation conform to Strict Provenance.
§Safety
Users must ensure that ItemEntry::into_raw
always produce *const ()
s that meet the above
alignment requirements.
Users must also ensure that as long as the value does not get dropped (e.g., by dropping the
value obtaining from ItemEntry::from_raw
), it is safe to invoke ItemEntry::raw_as_ref
multiple times to obtain values of ItemEntry::Ref
that behave just like shared references
to the underleying data.
Required Associated Types§
Required Methods§
Sourcefn into_raw(self) -> *const ()
fn into_raw(self) -> *const ()
Converts the original value into a *const ()
, consuming the ownership of the original
value.
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.