pub struct ErasedSendSet { /* private fields */ }Expand description
Like ErasedSet but with a Send bound.
§Example
use erased_set::ErasedSendSet;
let mut set = ErasedSendSet::new();
set.insert(ClickEvent(128, 256));
set.insert(KeyDownEvent('z'));
assert_eq!(set.get::<ClickEvent>(), Some(&ClickEvent(128, 256)));
assert_eq!(set.insert(KeyDownEvent('e')), Some(KeyDownEvent('z')));
set.remove::<ClickEvent>();
assert_eq!(set.len(), 1);Implementations§
Source§impl ErasedSendSet
impl ErasedSendSet
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty ErasedSendSet.
The set is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
§Examples
use erased_set::ErasedSendSet;
let set = ErasedSendSet::new();Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the set contains no instances of any type.
§Examples
use erased_set::ErasedSendSet;
let set = ErasedSendSet::new();
assert!(set.is_empty());Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of types in the set.
§Examples
use erased_set::ErasedSendSet;
let mut set = ErasedSendSet::new();
assert_eq!(set.len(), 0);
set.insert("a");
assert_eq!(set.len(), 1);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the set. Keep allocated memory for reuse.
§Examples
use erased_set::ErasedSendSet;
let mut set = ErasedSendSet::new();
set.insert("a");
set.clear();
assert!(set.is_empty());Sourcepub fn contains<T>(&self) -> boolwhere
T: Any,
pub fn contains<T>(&self) -> boolwhere
T: Any,
Returns true if the set contains an instance of T.
§Examples
use erased_set::ErasedSendSet;
let mut set = ErasedSendSet::new();
set.insert("a");
assert!(set.contains::<&str>());Sourcepub fn get_or_insert<T>(&mut self, value: T) -> &T
pub fn get_or_insert<T>(&mut self, value: T) -> &T
Inserts the given value into the set if it is not present, then
returns a reference to the value in the set.
§Examples
use erased_set::ErasedSendSet;
let mut set = ErasedSendSet::new();
assert_eq!(set.get_or_insert("abc"), &"abc");
assert_eq!(set.get_or_insert("def"), &"abc");Sourcepub fn get_or_insert_with<T>(&mut self, f: impl FnOnce() -> T) -> &T
pub fn get_or_insert_with<T>(&mut self, f: impl FnOnce() -> T) -> &T
Inserts a value computed from f into the set if it does not contain
a value of type T, then returns a reference to the value in the set.
§Examples
use erased_set::ErasedSendSet;
let mut set = ErasedSendSet::new();
assert_eq!(set.get_or_insert_with(|| String::from("abc")), &"abc");
assert_eq!(set.get_or_insert_with(|| String::from("def")), &"abc");Sourcepub fn type_ids(&self) -> impl Iterator<Item = &TypeId>
pub fn type_ids(&self) -> impl Iterator<Item = &TypeId>
Gets an iterator over the TypeIds of stored elements, in arbitrary order.
Sourcepub fn debug_type_names(&self) -> impl Iterator<Item = &'static str> + '_
pub fn debug_type_names(&self) -> impl Iterator<Item = &'static str> + '_
Gets an iterator over the names of the stored types, in arbitrary order.
Trait Implementations§
Source§impl Debug for ErasedSendSet
Available on crate feature send only.
impl Debug for ErasedSendSet
send only.