Trait persian_rug::Context
source · [−]pub trait Context {
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>ⓘNotable traits for TableIterator<'a, T>impl<'a, T> Iterator for TableIterator<'a, T> type Item = &'a T;
where
Self: Owner<T>,
T: Contextual<Context = Self>;
fn get_iter_mut<T>(&mut self) -> TableMutIterator<'_, T>ⓘNotable traits for TableMutIterator<'a, T>impl<'a, T> Iterator for TableMutIterator<'a, T> type Item = &'a mut T;
where
Self: Owner<T>,
T: Contextual<Context = Self>;
fn get_proxy_iter<T>(&self) -> TableProxyIterator<'_, T>ⓘNotable traits for TableProxyIterator<'a, T>impl<'a, T> Iterator for TableProxyIterator<'a, T> type Item = &'a Proxy<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
fn add<T>(&mut self, value: T) -> Proxy<T> where
Self: Owner<T>,
T: Contextual<Context = Self>,
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.
Retrieve a reference to a value from a Proxy
.
Retrieve a mutable reference to a value from a Proxy
.
fn get_iter<T>(&self) -> TableIterator<'_, T>ⓘNotable traits for TableIterator<'a, T>impl<'a, T> Iterator for TableIterator<'a, T> type Item = &'a T;
where
Self: Owner<T>,
T: Contextual<Context = Self>,
fn get_iter<T>(&self) -> TableIterator<'_, T>ⓘNotable traits for TableIterator<'a, T>impl<'a, T> Iterator for TableIterator<'a, T> type Item = &'a T;
where
Self: Owner<T>,
T: Contextual<Context = Self>,
Iterate over the values currently stored.
fn get_iter_mut<T>(&mut self) -> TableMutIterator<'_, T>ⓘNotable traits for TableMutIterator<'a, T>impl<'a, T> Iterator for TableMutIterator<'a, T> type Item = &'a mut T;
where
Self: Owner<T>,
T: Contextual<Context = Self>,
fn get_iter_mut<T>(&mut self) -> TableMutIterator<'_, T>ⓘNotable traits for TableMutIterator<'a, T>impl<'a, T> Iterator for TableMutIterator<'a, T> type Item = &'a mut T;
where
Self: Owner<T>,
T: Contextual<Context = Self>,
Mutably iterate over the values currently stored.
fn get_proxy_iter<T>(&self) -> TableProxyIterator<'_, T>ⓘNotable traits for TableProxyIterator<'a, T>impl<'a, T> Iterator for TableProxyIterator<'a, T> type Item = &'a Proxy<T>;
where
Self: Owner<T>,
T: Contextual<Context = Self>,
fn get_proxy_iter<T>(&self) -> TableProxyIterator<'_, T>ⓘNotable traits for TableProxyIterator<'a, T>impl<'a, T> Iterator for TableProxyIterator<'a, T> type Item = &'a Proxy<T>;
where
Self: Owner<T>,
T: Contextual<Context = Self>,
Iterate over (owned) proxies for the values currently stored.