[][src]Trait zc::Storage

pub unsafe trait Storage: Sized + Deref + 'static { }

Implemented for types that can safely provide a stable, aliasable reference to data they own.

noalias

The pointers behind common allocation types (Box<T>, Vec<T>, etc), are stored via core::ptr::Unique<T>, which passes to the compilier a noalias attribute. This attribute allows the compiler to make optimisations with the guarantee that no other pointers are referencing the same data.

We want to both own the data and provide a reference to it, outside of Rust's normal lifetime garantees, which can break with some of the optimisations the compiler can make. To achieve this, we need to remove the noalias attribute of the underlying pointer to let the compiler know that there will exist multiple pointers referencing the same owned data, which is also known as aliasing.

Safety

The implementer must guarantee that the reference it provides via Deref will be both stable and aliasable for the lifetime of self. Stable in this context meaning that the pointer to the data referenced will not change.

Box<T> provides a stable pointer (the location of the data being pointed to will not change) but is not aliasable (see noalias above). Instead we can use the basic wrapper types provided by the aliasable crate.

Implementations on Foreign Types

impl Storage for AliasableString[src]

impl<T: 'static> Storage for AliasableVec<T>[src]

impl<T: ?Sized + 'static> Storage for AliasableBox<T>[src]

Loading content...

Implementors

Loading content...