Skip to main content

Storage

Trait Storage 

Source
pub trait Storage {
    type Container<T>;

    // Required methods
    fn new<T>(t: T) -> Self::Container<T>;
    fn into_inner<T>(container: Self::Container<T>) -> T;
    fn as_ref<T>(container: &Self::Container<T>) -> &T;
    fn as_mut<T>(container: &mut Self::Container<T>) -> &mut T;
    fn clone<T>(container: &Self::Container<T>) -> Self::Container<T>
       where T: Clone;
}
Expand description

Generic data storage mechanism.

Currently an abstraction over Box storage (much more memory-efficient) and inlined structs (sometimes faster).

The particular structure of the trait (GAT for container type) is needed to enable the storage type to not carry a parameter, e.g. Node<T, InlineStorage> (rather than Node<T, InlineStorage<T>>). This is desirable to make type inference and trait derivation much more straightforward.

Required Associated Types§

Source

type Container<T>

The container type used to hold the value type.

Required Methods§

Source

fn new<T>(t: T) -> Self::Container<T>

Construct a new container.

Source

fn into_inner<T>(container: Self::Container<T>) -> T

Destruct the container to retrieve the contained value.

Source

fn as_ref<T>(container: &Self::Container<T>) -> &T

Retrieve a reference to the contained value.

Source

fn as_mut<T>(container: &mut Self::Container<T>) -> &mut T

Retrieve a mutable reference to the contained value.

Source

fn clone<T>(container: &Self::Container<T>) -> Self::Container<T>
where T: Clone,

Clone the container.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§