Collection

Struct Collection 

Source
pub struct Collection<In, Ix, S = DefaultStore<In>> { /* private fields */ }
Expand description

A collection of items, with an index that is automatically kept up-to-date.

Implementations§

Source§

impl<In, Ix> Collection<In, Ix>

Source

pub fn new(ix: Ix) -> Self
where In: 'static, Ix: Index<In>, DefaultStore<In>: Store<In>,

Create an empty collection.

Source§

impl<In, Ix, S: Default> Collection<In, Ix, S>

Source

pub fn new_with_empty_store(ix: Ix) -> Self

Create an empty collection.

Source§

impl<In, Ix, S> Collection<In, Ix, S>

Source

pub fn new_with_store(store: S, ix: Ix) -> Self

Create an empty collection with a custom store.

Source§

impl<In, Ix, S> Collection<In, Ix, S>
where In: 'static, Ix: Index<In>, S: Store<In>,

Source

pub fn get_by_key(&self, key: Key) -> Option<&In>

Lookup an item in the collection by its key.

Source

pub fn insert(&mut self, value: In) -> Key

Insert a new item into the collection.

Source

pub fn iter(&self) -> impl IntoIterator<Item = (Key, &In)>

Iterate over all items in the collection.

Source

pub fn update_by_key_mut<F>(&mut self, key: Key, f: F)
where F: FnOnce(&mut Option<In>),

Mutate (or alter the presence of) the item in the collection.

Source

pub fn update_by_key<F>(&mut self, key: Key, f: F)
where F: FnOnce(Option<&In>) -> In,

Update the item in the collection.

Source

pub fn adjust_by_key_mut<F>(&mut self, key: Key, f: F)
where F: FnOnce(&mut In),

Mutate the item in the collection, if it exists.

Source

pub fn adjust_by_key<F>(&mut self, key: Key, f: F)
where F: FnOnce(&In) -> In,

Adjust the item in the collection, if it exists.

Source

pub fn delete_by_key(&mut self, key: Key) -> Option<In>

Remove an item from the collection, returning it if it exists.

Source

pub fn query<Res>(&self, f: impl FnOnce(&Ix) -> Res) -> Res::Resolved<&In>
where Res: QueryResult,

Query the collection using its index(es).

Source

pub fn delete<Res>(&mut self, f: impl FnOnce(&Ix) -> Res) -> usize
where Res: QueryResult,

Source

pub fn update<Res, F>( &mut self, f: impl FnOnce(&Ix) -> Res, update_fn: impl Fn(&In) -> In, ) -> Res::Resolved<()>

Source

pub fn take<Res>(&mut self, f: impl FnOnce(&Ix) -> Res) -> Res::Resolved<In>

Source

pub fn len(&self) -> usize

Number of items in the collection.

Source

pub fn is_empty(&self) -> bool

Auto Trait Implementations§

§

impl<In, Ix, S> Freeze for Collection<In, Ix, S>
where Ix: Freeze, S: Freeze,

§

impl<In, Ix, S> RefUnwindSafe for Collection<In, Ix, S>

§

impl<In, Ix, S> Send for Collection<In, Ix, S>
where Ix: Send, S: Send,

§

impl<In, Ix, S> Sync for Collection<In, Ix, S>
where Ix: Sync, S: Sync,

§

impl<In, Ix, S> Unpin for Collection<In, Ix, S>
where Ix: Unpin, S: Unpin,

§

impl<In, Ix, S> UnwindSafe for Collection<In, Ix, S>
where Ix: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.