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.
sourceunsafe fn from_raw(raw: *const ()) -> Self
unsafe fn from_raw(raw: *const ()) -> Self
Recovers the original value from a *const ()
, reclaiming the ownership of the original
value.
§Safety
The original value must have not been dropped, and all references obtained from
ItemEntry::raw_as_ref
must be dead.
sourceunsafe fn raw_as_ref<'a>(raw: *const ()) -> Self::Ref<'a>
unsafe fn raw_as_ref<'a>(raw: *const ()) -> Self::Ref<'a>
Obtains a shared reference to the original value.
§Safety
The original value must outlive the lifetime parameter 'a
, and during 'a
no mutable
references to the value will exist.