Trait persian_rug::Context

source ·
pub trait Context {
    // Required methods
    fn add<T>(&mut self, value: T) -> Proxy<T>
       where Self: Owner<T>,
             T: Contextual<Context = Self>;
    fn get<T>(&self, what: &Proxy<T>) -> &T
       where Self: Owner<T>,
             T: Contextual<Context = Self>;
    fn get_mut<T>(&mut self, what: &Proxy<T>) -> &mut T
       where Self: Owner<T>,
             T: Contextual<Context = Self>;
    fn get_iter<T>(&self) -> TableIterator<'_, T> 
       where Self: Owner<T>,
             T: Contextual<Context = Self>;
    fn get_iter_mut<T>(&mut self) -> TableMutIterator<'_, T> 
       where Self: Owner<T>,
             T: Contextual<Context = Self>;
    fn get_proxy_iter<T>(&self) -> TableProxyIterator<'_, T> 
       where Self: Owner<T>,
             T: Contextual<Context = Self>;
}
Expand description

A holder for Contextual types.

This is the “rug” in persian-rug (and in the examples, the context is often called Rug). The implementor is the sole owner for the Contextual objects it contains, and is responsible for resolving Proxy objects into references to its owned copies.

You will not generally implement this trait directly. The persian_rug attribute macro sets up the necessary implementations for a usable Context, converting each marked field into a Table, and providing an implementation of Owner for each included type.

A context should only have one field of a given type. Its purpose is to conveniently resolve Proxy objects and hold data; actual data organisation ought to be done in a different object, by holding whatever objects are required, in whatever organisation is required, as proxies.

Required Methods§

source

fn add<T>(&mut self, value: T) -> Proxy<T>
where Self: Owner<T>, T: Contextual<Context = Self>,

Insert the given value, returning a Proxy for it.

source

fn get<T>(&self, what: &Proxy<T>) -> &T
where Self: Owner<T>, T: Contextual<Context = Self>,

Retrieve a reference to a value from a Proxy.

source

fn get_mut<T>(&mut self, what: &Proxy<T>) -> &mut T
where Self: Owner<T>, T: Contextual<Context = Self>,

Retrieve a mutable reference to a value from a Proxy.

source

fn get_iter<T>(&self) -> TableIterator<'_, T>
where Self: Owner<T>, T: Contextual<Context = Self>,

Iterate over the values currently stored.

source

fn get_iter_mut<T>(&mut self) -> TableMutIterator<'_, T>
where Self: Owner<T>, T: Contextual<Context = Self>,

Mutably iterate over the values currently stored.

source

fn get_proxy_iter<T>(&self) -> TableProxyIterator<'_, T>
where Self: Owner<T>, T: Contextual<Context = Self>,

Iterate over (owned) proxies for the values currently stored.

Object Safety§

This trait is not object safe.

Implementors§