Trait xarray::ItemEntry

source ·
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§

source

type Ref<'a>: Deref<Target = Self> where Self: 'a

A type that behaves just like a shared references to the underleying data.

Required Methods§

source

fn into_raw(self) -> *const ()

Converts the original value into a *const (), consuming the ownership of the original value.

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> ItemEntry for Arc<T>

§

type Ref<'a> = ArcRef<'a, T> where Self: 'a

source§

fn into_raw(self) -> *const ()

source§

unsafe fn from_raw(raw: *const ()) -> Self

source§

unsafe fn raw_as_ref<'a>(raw: *const ()) -> Self::Ref<'a>

source§

impl<T> ItemEntry for Box<T>

§

type Ref<'a> = BoxRef<'a, T> where Self: 'a

source§

fn into_raw(self) -> *const ()

source§

unsafe fn from_raw(raw: *const ()) -> Self

source§

unsafe fn raw_as_ref<'a>(raw: *const ()) -> Self::Ref<'a>

Implementors§