Trait freya::prelude::AnyStorage

pub trait AnyStorage: Default {
    type Ref<T: 'static + ?Sized>: Deref<Target = T> + 'static;
    type Mut<T: 'static + ?Sized>: DerefMut<Target = T> + 'static;

    // Required methods
    fn try_map_mut<T, U>(
        mut_ref: Self::Mut<T>,
        f: impl FnOnce(&mut T) -> Option<&mut U>
    ) -> Option<Self::Mut<U>>
       where U: 'static + ?Sized,
             T: ?Sized;
    fn try_map<T, U>(
        ref_: Self::Ref<T>,
        f: impl FnOnce(&T) -> Option<&U>
    ) -> Option<Self::Ref<U>>
       where U: 'static + ?Sized,
             T: ?Sized;
    fn data_ptr(&self) -> *const ();
    fn manually_drop(&self) -> bool;
    fn recycle(location: &MemoryLocation<Self>);
    fn claim() -> MemoryLocation<Self>;

    // Provided methods
    fn map_mut<T, U>(
        mut_ref: Self::Mut<T>,
        f: impl FnOnce(&mut T) -> &mut U
    ) -> Self::Mut<U>
       where U: 'static + ?Sized,
             T: ?Sized { ... }
    fn map<T, U>(ref_: Self::Ref<T>, f: impl FnOnce(&T) -> &U) -> Self::Ref<U>
       where U: 'static + ?Sized,
             T: ?Sized { ... }
    fn owner() -> Owner<Self> { ... }
}
Expand description

A trait for any storage backing type.

Required Associated Types§

type Ref<T: 'static + ?Sized>: Deref<Target = T> + 'static

The reference this storage type returns.

type Mut<T: 'static + ?Sized>: DerefMut<Target = T> + 'static

The mutable reference this storage type returns.

Required Methods§

fn try_map_mut<T, U>( mut_ref: Self::Mut<T>, f: impl FnOnce(&mut T) -> Option<&mut U> ) -> Option<Self::Mut<U>>
where U: 'static + ?Sized, T: ?Sized,

Try to map the mutable ref.

fn try_map<T, U>( ref_: Self::Ref<T>, f: impl FnOnce(&T) -> Option<&U> ) -> Option<Self::Ref<U>>
where U: 'static + ?Sized, T: ?Sized,

Try to map the ref.

fn data_ptr(&self) -> *const ()

Get the data pointer. No guarantees are made about the data pointer. It should only be used for debugging.

fn manually_drop(&self) -> bool

Drop the value from the storage. This will return true if the value was taken.

fn recycle(location: &MemoryLocation<Self>)

Recycle a memory location. This will drop the memory location and return it to the runtime.

fn claim() -> MemoryLocation<Self>

Claim a new memory location. This will either create a new memory location or recycle an old one.

Provided Methods§

fn map_mut<T, U>( mut_ref: Self::Mut<T>, f: impl FnOnce(&mut T) -> &mut U ) -> Self::Mut<U>
where U: 'static + ?Sized, T: ?Sized,

Map the mutable ref.

fn map<T, U>(ref_: Self::Ref<T>, f: impl FnOnce(&T) -> &U) -> Self::Ref<U>
where U: 'static + ?Sized, T: ?Sized,

Map the ref.

fn owner() -> Owner<Self>

Create a new owner. The owner will be responsible for dropping all of the generational boxes that it creates.

Object Safety§

This trait is not object safe.

Implementors§

§

impl AnyStorage for SyncStorage

§

type Ref<R: 'static + ?Sized> = GenerationalRef<MappedRwLockReadGuard<'static, RawRwLock, R>>

§

type Mut<W: 'static + ?Sized> = GenerationalRefMut<MappedRwLockWriteGuard<'static, RawRwLock, W>>

§

impl AnyStorage for UnsyncStorage

§

type Ref<R: 'static + ?Sized> = GenerationalRef<Ref<'static, R>>

§

type Mut<W: 'static + ?Sized> = GenerationalRefMut<RefMut<'static, W>>