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>

source

pub fn new() -> Self

Create a new table.

Tables are created empty.

source

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.

source

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.

source

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.

source

pub fn iter(&self) -> TableIterator<'_, T>

Iterate over shared references to all stored items.

source

pub fn iter_mut(&mut self) -> TableMutIterator<'_, T>

Iterate over mutable references to all stored items.

source

pub fn iter_proxies(&self) -> TableProxyIterator<'_, T>

Iterate over proxies for all stored items.

Note that Proxy implements Copy so that although this returns references, you can cheaply convert them to owned values as required with the copied method on Iterator.

Trait Implementations§

source§

impl<T: Clone> Clone for Table<T>

source§

fn clone(&self) -> Table<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Table<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for Table<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Table<T>

§

impl<T> RefUnwindSafe for Table<T>
where T: RefUnwindSafe,

§

impl<T> Send for Table<T>
where T: Send,

§

impl<T> Sync for Table<T>
where T: Sync,

§

impl<T> Unpin for Table<T>
where T: Unpin,

§

impl<T> UnwindSafe for Table<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.