pub struct Collection<In, Ix, S = HashMap<Key, In, DefaultHashBuilder>> { /* 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>
Source§impl<In, Ix, S: Default> Collection<In, Ix, S>
impl<In, Ix, S: Default> Collection<In, Ix, S>
Sourcepub fn new_with_empty_store(ix: Ix) -> Self
pub fn new_with_empty_store(ix: Ix) -> Self
Create an empty collection.
Source§impl<In, Ix, S> Collection<In, Ix, S>
impl<In, Ix, S> Collection<In, Ix, S>
Sourcepub fn new_with_store(store: S, ix: Ix) -> Self
pub fn new_with_store(store: S, ix: Ix) -> Self
Create a collection with a custom store.
If the store is non-empty, the indexes will be populated from the store’s contents. So this may be an expensive operation depending on the size of the store.
Source§impl<In, Ix, S> Collection<In, Ix, S>
impl<In, Ix, S> Collection<In, Ix, S>
Sourcepub fn extract_store(self) -> S
pub fn extract_store(self) -> S
Extract the underlying store.
Sourcepub fn unsafe_mut_store(&mut self) -> &mut S
pub fn unsafe_mut_store(&mut self) -> &mut S
Mutably access the underlying store. Warning: Mutating the elements inside the store may lead to inconsistencies with the index and cause undefined behavior. Use with caution. Ideally - only use it in a way that doesn’t modify the elements.
Source§impl<In, Ix, S> Collection<In, Ix, S>
impl<In, Ix, S> Collection<In, Ix, S>
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 insert_all<I>(&mut self, iter: I)where
I: Iterator<Item = In>,
pub fn insert_all<I>(&mut self, iter: I)where
I: Iterator<Item = In>,
Insert all items from an iterator into the collection.
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::Resolved<&In>where
Res: QueryResult,
pub fn query<Res>(&self, f: impl FnOnce(&Ix) -> Res) -> Res::Resolved<&In>where
Res: QueryResult,
Perform a query using the collection’s indexes, returning references to the items.
Sourcepub fn query_keys<Res>(&self, f: impl FnOnce(&Ix) -> Res) -> Res::Resolved<Key>where
Res: QueryResult,
pub fn query_keys<Res>(&self, f: impl FnOnce(&Ix) -> Res) -> Res::Resolved<Key>where
Res: QueryResult,
Perform a query using the collection’s indexes, returning the keys of the items.
Sourcepub fn query_with_keys<Res>(
&self,
f: impl FnOnce(&Ix) -> Res,
) -> Res::Resolved<(Key, &In)>where
Res: QueryResult,
pub fn query_with_keys<Res>(
&self,
f: impl FnOnce(&Ix) -> Res,
) -> Res::Resolved<(Key, &In)>where
Res: QueryResult,
Perform a query using the collection’s indexes, returning both the keys and the items.
Sourcepub fn delete<Res>(&mut self, f: impl FnOnce(&Ix) -> Res) -> usizewhere
Res: QueryResult,
pub fn delete<Res>(&mut self, f: impl FnOnce(&Ix) -> Res) -> usizewhere
Res: QueryResult,
Delete all items matching the query.
Sourcepub fn update<Res, F>(
&mut self,
f: impl FnOnce(&Ix) -> Res,
update_fn: impl Fn(&In) -> In,
) -> Res::Resolved<()>where
Res: QueryResultDistinct,
pub fn update<Res, F>(
&mut self,
f: impl FnOnce(&Ix) -> Res,
update_fn: impl Fn(&In) -> In,
) -> Res::Resolved<()>where
Res: QueryResultDistinct,
Update all items matching the query with the provided function.
Sourcepub fn take<Res>(&mut self, f: impl FnOnce(&Ix) -> Res) -> Res::Resolved<In>where
Res: QueryResultDistinct,
pub fn take<Res>(&mut self, f: impl FnOnce(&Ix) -> Res) -> Res::Resolved<In>where
Res: QueryResultDistinct,
Remove and return all items matching the query.
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl<In: Clone, Ix: Clone, S: Clone> Clone for Collection<In, Ix, S>
impl<In: Clone, Ix: Clone, S: Clone> Clone for Collection<In, Ix, S>
Source§fn clone(&self) -> Collection<In, Ix, S>
fn clone(&self) -> Collection<In, Ix, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<In, Ix, S> ShallowClone for Collection<In, Ix, S>
impl<In, Ix, S> ShallowClone for Collection<In, Ix, S>
fn shallow_clone(&self) -> Self
Auto Trait Implementations§
impl<In, Ix, S> Freeze for Collection<In, Ix, S>
impl<In, Ix, S> RefUnwindSafe for Collection<In, Ix, S>where
Ix: RefUnwindSafe,
S: RefUnwindSafe,
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>where
Ix: UnwindSafe,
S: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);