pub struct Collection<In, Ix, S = RandomState> { /* 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>
impl<In, Ix> Collection<In, Ix>
Sourcepub fn new(ix: Ix) -> Collection<In, Ix>
pub fn new(ix: Ix) -> Collection<In, Ix>
Create an empty collection.
Source§impl<In, Ix, S> Collection<In, Ix, S>where
S: BuildHasher,
impl<In, Ix, S> Collection<In, Ix, S>where
S: BuildHasher,
Sourcepub fn new_with_hasher(hasher: S, ix: Ix) -> Collection<In, Ix, S>
pub fn new_with_hasher(hasher: S, ix: Ix) -> Collection<In, Ix, S>
Create an empty collection with a custom hasher.
Source§impl<In, Ix> Collection<In, Ix>where
Ix: Index<In>,
impl<In, Ix> Collection<In, Ix>where
Ix: Index<In>,
Sourcepub fn get_by_key(&self, key: Key) -> Option<&In>
pub fn get_by_key(&self, key: Key) -> Option<&In>
Lookup an item in the collection by its key.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Key, &In)>
pub fn iter(&self) -> impl Iterator<Item = (&Key, &In)>
Iterate over all items in the collection.
Sourcepub fn update_by_key_mut<F>(&mut self, key: Key, f: F)
pub fn update_by_key_mut<F>(&mut self, key: Key, f: F)
Mutate (or alter the presence of) the item in the collection.
Sourcepub fn update_by_key<F>(&mut self, key: Key, f: F)
pub fn update_by_key<F>(&mut self, key: Key, f: F)
Update the item in the collection.
Sourcepub fn adjust_by_key_mut<F>(&mut self, key: Key, f: F)
pub fn adjust_by_key_mut<F>(&mut self, key: Key, f: F)
Mutate the item in the collection, if it exists.
Sourcepub fn adjust_by_key<F>(&mut self, key: Key, f: F)
pub fn adjust_by_key<F>(&mut self, key: Key, f: F)
Adjust the item in the collection, if it exists.
Sourcepub fn delete_by_key(&mut self, key: &Key) -> Option<In>
pub fn delete_by_key(&mut self, key: &Key) -> Option<In>
Remove an item from the collection, returning it if it exists.
Sourcepub fn query<Res>(
&self,
f: impl FnOnce(&Ix) -> Res,
) -> <Res as QueryResult>::Resolved<&In>where
Res: QueryResult,
pub fn query<Res>(
&self,
f: impl FnOnce(&Ix) -> Res,
) -> <Res as QueryResult>::Resolved<&In>where
Res: QueryResult,
Query the collection using its index(es).
pub fn delete<Res>(&mut self, f: impl FnOnce(&Ix) -> Res) -> usizewhere
Res: QueryResult,
pub fn update<Res, F>(
&mut self,
f: impl FnOnce(&Ix) -> Res,
update_fn: impl Fn(&In) -> In,
) -> <Res as QueryResult>::Resolved<()>where
Res: QueryResultDistinct,
pub fn take<Res>(
&mut self,
f: impl FnOnce(&Ix) -> Res,
) -> <Res as QueryResult>::Resolved<In>where
Res: QueryResultDistinct,
pub fn is_empty(&self) -> bool
Auto Trait Implementations§
impl<In, Ix, S> Freeze for Collection<In, Ix, S>
impl<In, Ix, S> RefUnwindSafe for Collection<In, Ix, S>
impl<In, Ix, S> Send for Collection<In, Ix, S>
impl<In, Ix, S> Sync for Collection<In, Ix, S>
impl<In, Ix, S> Unpin for Collection<In, Ix, S>
impl<In, Ix, S> UnwindSafe for Collection<In, Ix, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more