Skip to main content

Storage

Trait Storage 

Source
pub trait Storage<T>:
    Send
    + Sync
    + 'static {
    type Wrapped: StorageAccess<T> + Send + Sync + 'static;

    // Required methods
    fn wrap(value: T) -> Self::Wrapped;
    fn try_with<U>(node: NodeId, fun: impl FnOnce(&T) -> U) -> Option<U>;
    fn try_with_mut<U>(node: NodeId, fun: impl FnOnce(&mut T) -> U) -> Option<U>;
    fn try_set(node: NodeId, value: T) -> Option<T>;
    fn take(node: NodeId) -> Option<T>;
}
Expand description

A way of storing an ArenaItem, either as itself or with a wrapper to make it threadsafe.

This exists because all items stored in the arena must be Send + Sync, but in single-threaded environments you might want or need to use thread-unsafe types.

Required Associated Types§

Source

type Wrapped: StorageAccess<T> + Send + Sync + 'static

The type being stored, once it has been wrapped.

Required Methods§

Source

fn wrap(value: T) -> Self::Wrapped

Adds any needed wrapper to the type.

Source

fn try_with<U>(node: NodeId, fun: impl FnOnce(&T) -> U) -> Option<U>

Applies the given function to the stored value, if it exists and can be accessed from this thread.

Source

fn try_with_mut<U>(node: NodeId, fun: impl FnOnce(&mut T) -> U) -> Option<U>

Applies the given function to a mutable reference to the stored value, if it exists and can be accessed from this thread.

Source

fn try_set(node: NodeId, value: T) -> Option<T>

Sets a new value for the stored value. If it has been disposed, returns Some(T).

Source

fn take(node: NodeId) -> Option<T>

Takes an item from the arena if it exists and can be accessed from this thread. If it cannot be casted, it will still be removed from the arena.

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.

Implementors§

Source§

impl<T> Storage<T> for LocalStorage
where T: 'static,

Source§

impl<T> Storage<T> for SyncStorage
where T: Send + Sync + 'static,