Struct persian_rug::Table
source · pub struct Table<T> { /* private fields */ }
Expand description
A holder for Contextual
objects.
It is unlikely that you will ever need to instantiate this class,
unless for some reason the persian_rug
attribute macro which
creates Context
implementations is not suitable for your use.
A context object will generally have one table per object type,
and that table does the work of storing, retrieving and iterating
over objects of that type, and the Proxy
objects that refer to
them.
Implementations§
source§impl<T> Table<T>
impl<T> Table<T>
sourcepub fn push(&mut self, value: T) -> Proxy<T>
pub fn push(&mut self, value: T) -> Proxy<T>
Insert a new item.
The return value is a Proxy
that you can store, and later
use to retrieve the stored object from the table.
sourcepub fn get(&self, p: &Proxy<T>) -> Option<&T>
pub fn get(&self, p: &Proxy<T>) -> Option<&T>
Retrieve a previously stored item.
Note that the return value is an Option
, because not all
Proxy
objects of a given type can be necessarily retrieved
from a given Table
. This is clearly the ideal however, and
Context
implementations created with the persian_rug
attribute macro unwrap this return value, causing a panic on
failure.
sourcepub fn get_mut(&mut self, p: &Proxy<T>) -> Option<&mut T>
pub fn get_mut(&mut self, p: &Proxy<T>) -> Option<&mut T>
Retrieve a previously stored item mutably.
Note that the return value is an Option
, because not all
Proxy
objects of a given type can be necessarily retrieved
from a given Table
. This is clearly the ideal however, and
Context
implementations created with the persian_rug
attribute macro unwrap this return value, causing a panic on
failure.
sourcepub fn iter(&self) -> TableIterator<'_, T> ⓘ
pub fn iter(&self) -> TableIterator<'_, T> ⓘ
Iterate over shared references to all stored items.
sourcepub fn iter_mut(&mut self) -> TableMutIterator<'_, T> ⓘ
pub fn iter_mut(&mut self) -> TableMutIterator<'_, T> ⓘ
Iterate over mutable references to all stored items.