pub struct Collected<K, V> { /* private fields */ }Expand description
What the collecting shortcuts return (D-268): the Collection of what was collected
(through Deref) and why the collector ended. An empty result is not an error.
discord.js counterpart: the Collection of awaitMessages / awaitReactions.
Implementations§
Source§impl<K, V> Collected<K, V>
impl<K, V> Collected<K, V>
Sourcepub const fn reason(&self) -> EndReason
pub const fn reason(&self) -> EndReason
Why the collector ended.
discord.js counterpart: the reason of a collector’s end event.
Sourcepub fn into_collection(self) -> Collection<K, V>
pub fn into_collection(self) -> Collection<K, V>
Returns the collection.
discord.js counterpart: the Collection awaitMessages and awaitReactions resolve to.
Methods from Deref<Target = Collection<K, V>>§
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether there are no entries.
discord.js counterpart: collection.size === 0.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
How many entries fit before the collection reallocates.
discord.js counterpart: none (JavaScript maps have no capacity).
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes every entry, keeping the memory for reuse.
discord.js counterpart: clear.
Sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
The hasher keys are hashed with.
discord.js counterpart: none (JavaScript maps have no hasher).
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
The entries in order, as (&key, &value).
discord.js counterpart: entries.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
The entries in order, with mutable values.
discord.js counterpart: none (JavaScript values are mutated in place).
Sourcepub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
The values in order.
discord.js counterpart: values.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
The values in order, mutable.
discord.js counterpart: none (JavaScript values are mutated in place).
Sourcepub fn as_index_map(&self) -> &IndexMap<K, V, S>
pub fn as_index_map(&self) -> &IndexMap<K, V, S>
The inner IndexMap, for operations this type does not offer (D-217).
discord.js counterpart: none (the Map a Collection extends).
Sourcepub fn as_index_map_mut(&mut self) -> &mut IndexMap<K, V, S>
pub fn as_index_map_mut(&mut self) -> &mut IndexMap<K, V, S>
The inner IndexMap, mutable (D-217).
discord.js counterpart: none (the Map a Collection extends).
Sourcepub fn first(&self) -> Option<&V>
pub fn first(&self) -> Option<&V>
The first value inserted, or None if the collection is empty. The first n are
.values().take(n).
discord.js counterpart: first().
Sourcepub fn first_key(&self) -> Option<&K>
pub fn first_key(&self) -> Option<&K>
The first key inserted.
discord.js counterpart: firstKey().
Sourcepub fn last(&self) -> Option<&V>
pub fn last(&self) -> Option<&V>
The last value inserted. The last n are .values().rev().take(n).
discord.js counterpart: last().
Sourcepub fn at(&self, index: isize) -> Option<&V>
pub fn at(&self, index: isize) -> Option<&V>
The value at position index in insertion order; a negative index counts from the
end (-1 is the last).
discord.js counterpart: at.
§Examples
use djs_collection::Collection;
let letters: Collection<u8, char> = [(1, 'a'), (2, 'b'), (3, 'c')].into();
assert_eq!(letters.at(0), Some(&'a'));
assert_eq!(letters.at(-1), Some(&'c'));
assert_eq!(letters.at(3), None);
assert_eq!(letters.key_at(-3), Some(&1));Sourcepub fn key_at(&self, index: isize) -> Option<&K>
pub fn key_at(&self, index: isize) -> Option<&K>
The key at position index; a negative index counts from the end.
discord.js counterpart: keyAt.
Sourcepub fn random(&self) -> Option<&V>
pub fn random(&self) -> Option<&V>
A random value, or None if the collection is empty.
The randomness comes from std’s RandomState (D-210): fine for games and giveaways,
not for anything that must resist prediction.
discord.js counterpart: random().
Sourcepub fn random_key(&self) -> Option<&K>
pub fn random_key(&self) -> Option<&K>
A random key.
discord.js counterpart: randomKey().
Sourcepub fn random_n(&self, count: usize) -> Vec<&V>
pub fn random_n(&self, count: usize) -> Vec<&V>
Up to count different random values, in random order — all of them, shuffled, if
count is at least the length.
discord.js counterpart: random(amount).
§Examples
use djs_collection::Collection;
let entrants: Collection<u64, &str> = [(1, "ada"), (2, "grace"), (3, "linus")].into();
let winners = entrants.random_n(2);
assert_eq!(winners.len(), 2);
assert_ne!(winners[0], winners[1]);Sourcepub fn find(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&V>
pub fn find(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&V>
The first value for which predicate(value, key) is true.
discord.js counterpart: find.
Sourcepub fn find_key(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&K>
pub fn find_key(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&K>
The key of the first value for which predicate(value, key) is true.
discord.js counterpart: findKey.
Sourcepub fn find_last(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&V>
pub fn find_last(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&V>
The last value for which predicate(value, key) is true.
discord.js counterpart: findLast.
Sourcepub fn find_last_key(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&K>
pub fn find_last_key(&self, predicate: impl FnMut(&V, &K) -> bool) -> Option<&K>
The key of the last value for which predicate(value, key) is true.
discord.js counterpart: findLastKey.
Sourcepub fn map<T>(&self, f: impl FnMut(&V, &K) -> T) -> Vec<T>
pub fn map<T>(&self, f: impl FnMut(&V, &K) -> T) -> Vec<T>
f(value, key) of every entry, in order.
discord.js counterpart: map.
§Examples
use djs_collection::Collection;
let users: Collection<u64, &str> = [(1, "ada"), (2, "grace")].into();
assert_eq!(users.map(|name, id| format!("{id}:{name}")), ["1:ada", "2:grace"]);Sourcepub fn sort_by(&mut self, compare: impl FnMut(&V, &V, &K, &K) -> Ordering)
pub fn sort_by(&mut self, compare: impl FnMut(&V, &V, &K, &K) -> Ordering)
Sorts the entries with compare(value_a, value_b, key_a, key_b), keeping the order of
equal ones.
discord.js counterpart: sort(compareFunction).
Sourcepub fn sort(&mut self)where
V: Ord,
pub fn sort(&mut self)where
V: Ord,
Sorts the entries by value, keeping the order of equal ones.
discord.js counterpart: sort() (which compares values as strings).
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
The value of key, mutable.
discord.js counterpart: none (JavaScript values are mutated in place).
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
The stored key equal to key, with its value.
discord.js counterpart: none (Map#get returns the value only).
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Whether key has a value.
discord.js counterpart: has.
Sourcepub fn index_of<Q>(&self, key: &Q) -> Option<usize>
pub fn index_of<Q>(&self, key: &Q) -> Option<usize>
The position of key in insertion order.
discord.js counterpart: none (the inverse of Collection#keyAt).
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Sets the value of key, returning the previous one. A new key goes last; an existing
key keeps its position.
discord.js counterpart: set.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes key, returning its value; the entries after it move up, so the order is
kept (O(n), D-215). swap_remove is O(1).
To remove many entries, use one sweep or retain
pass, which is linear however many it removes: removing 1 000 entries near the front
of a million one by one moves the rest 1 000 times (seconds instead of milliseconds).
discord.js counterpart: delete.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes key, returning the stored key and its value, keeping the order.
discord.js counterpart: Map#delete.
Sourcepub fn swap_remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<V>
Removes key in O(1) by moving the last entry into its place, so the order changes.
discord.js counterpart: none (Map#delete keeps the order).
Sourcepub fn ensure(&mut self, key: K, default: impl FnOnce(&K) -> V) -> &mut V
pub fn ensure(&mut self, key: K, default: impl FnOnce(&K) -> V) -> &mut V
The value of key, inserting default(&key) first if there is none.
discord.js counterpart: ensure.
§Examples
use djs_collection::Collection;
let mut warnings: Collection<u64, u32> = Collection::new();
*warnings.ensure(1, |_| 0) += 1;
*warnings.ensure(1, |_| 0) += 1;
assert_eq!(warnings.get(&1), Some(&2));Sourcepub fn has_all<'q, Q>(&self, keys: impl IntoIterator<Item = &'q Q>) -> bool
pub fn has_all<'q, Q>(&self, keys: impl IntoIterator<Item = &'q Q>) -> bool
Whether every key of keys has a value.
discord.js counterpart: hasAll.
Sourcepub fn has_any<'q, Q>(&self, keys: impl IntoIterator<Item = &'q Q>) -> bool
pub fn has_any<'q, Q>(&self, keys: impl IntoIterator<Item = &'q Q>) -> bool
Whether any key of keys has a value.
discord.js counterpart: hasAny.
Sourcepub fn retain(&mut self, keep: impl FnMut(&K, &mut V) -> bool)
pub fn retain(&mut self, keep: impl FnMut(&K, &mut V) -> bool)
Keeps only the entries for which keep(&key, &mut value) is true, in one pass that
keeps the order.
discord.js counterpart: Collection#sweep, with the condition inverted.
Sourcepub fn sweep(&mut self, remove: impl FnMut(&V, &K) -> bool) -> usize
pub fn sweep(&mut self, remove: impl FnMut(&V, &K) -> bool) -> usize
Removes the entries for which remove(value, key) is true, in one pass that keeps the
order, and returns how many were removed.
discord.js counterpart: sweep.
§Examples
use djs_collection::Collection;
let mut ages: Collection<&str, u32> = [("a", 3), ("b", 40), ("c", 7)].into();
assert_eq!(ages.sweep(|&age, _| age < 10), 2);
assert_eq!(ages.len(), 1);Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for Collected<K, V>
impl<K, V> RefUnwindSafe for Collected<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for Collected<K, V>
impl<K, V> Sync for Collected<K, V>
impl<K, V> Unpin for Collected<K, V>
impl<K, V> UnsafeUnpin for Collected<K, V>
impl<K, V> UnwindSafe for Collected<K, V>where
K: UnwindSafe,
V: 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Classify for T
impl<T> Classify for T
type Classified = T
fn classify(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more