Struct Components
pub struct Components(/* private fields */);
Implementations§
§impl Components
impl Components
pub fn merge<C>(
&self,
component_to_merge: C,
) -> Result<Component, ComponentMergeError>where
C: Into<Component>,
pub fn namespaces(&self) -> DashSet<String>
pub fn get<T>(&self, ty: T) -> Option<Component>where
T: Into<ComponentTypeId>,
pub fn get_by_namespace<N>(&self, namespace: N) -> Components
pub fn get_by_types<C>(&self, tys: C) -> Componentswhere
C: Into<ComponentTypeIds>,
pub fn find_by_type_name(&self, search: &str) -> Components
pub fn count_by_namespace<N>(&self, namespace: N) -> usize
Methods from Deref<Target = DashMap<ComponentTypeId, Component>>§
pub fn par_iter_mut(&self) -> IterMut<'_, K, V>
pub fn hash_usize<T>(&self, item: &T) -> usizewhere
T: Hash,
pub fn hash_usize<T>(&self, item: &T) -> usizewhere
T: Hash,
Hash a given item to produce a usize. Uses the provided or default HashBuilder.
pub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
§Examples
use dashmap::DashMap;
use std::collections::hash_map::RandomState;
let hasher = RandomState::new();
let map: DashMap<i32, i32> = DashMap::new();
let hasher: &RandomState = map.hasher();
pub fn insert(&self, key: K, value: V) -> Option<V>
pub fn insert(&self, key: K, value: V) -> Option<V>
Inserts a key and a value into the map. Returns the old value associated with the key if there was one.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let map = DashMap::new();
map.insert("I am the key!", "And I am the value!");
pub fn remove<Q>(&self, key: &Q) -> Option<(K, V)>
pub fn remove<Q>(&self, key: &Q) -> Option<(K, V)>
Removes an entry from the map, returning the key and value if they existed in the map.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let soccer_team = DashMap::new();
soccer_team.insert("Jack", "Goalie");
assert_eq!(soccer_team.remove("Jack").unwrap().1, "Goalie");
pub fn remove_if<Q>(
&self,
key: &Q,
f: impl FnOnce(&K, &V) -> bool,
) -> Option<(K, V)>
pub fn remove_if<Q>( &self, key: &Q, f: impl FnOnce(&K, &V) -> bool, ) -> Option<(K, V)>
Removes an entry from the map, returning the key and value if the entry existed and the provided conditional function returned true.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
use dashmap::DashMap;
let soccer_team = DashMap::new();
soccer_team.insert("Sam", "Forward");
soccer_team.remove_if("Sam", |_, position| position == &"Goalie");
assert!(soccer_team.contains_key("Sam"));
use dashmap::DashMap;
let soccer_team = DashMap::new();
soccer_team.insert("Sam", "Forward");
soccer_team.remove_if("Sam", |_, position| position == &"Forward");
assert!(!soccer_team.contains_key("Sam"));
pub fn remove_if_mut<Q>( &self, key: &Q, f: impl FnOnce(&K, &mut V) -> bool, ) -> Option<(K, V)>
pub fn iter(&'a self) -> Iter<'a, K, V, S>
pub fn iter(&'a self) -> Iter<'a, K, V, S>
Creates an iterator over a DashMap yielding immutable references.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let words = DashMap::new();
words.insert("hello", "world");
assert_eq!(words.iter().count(), 1);
pub fn iter_mut(&'a self) -> IterMut<'a, K, V, S>
pub fn iter_mut(&'a self) -> IterMut<'a, K, V, S>
Iterator over a DashMap yielding mutable references.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let map = DashMap::new();
map.insert("Johnny", 21);
map.iter_mut().for_each(|mut r| *r += 1);
assert_eq!(*map.get("Johnny").unwrap(), 22);
pub fn get<Q>(&'a self, key: &Q) -> Option<Ref<'a, K, V>>
pub fn get<Q>(&'a self, key: &Q) -> Option<Ref<'a, K, V>>
Get an immutable reference to an entry in the map
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let youtubers = DashMap::new();
youtubers.insert("Bosnian Bill", 457000);
assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), 457000);
pub fn get_mut<Q>(&'a self, key: &Q) -> Option<RefMut<'a, K, V>>
pub fn get_mut<Q>(&'a self, key: &Q) -> Option<RefMut<'a, K, V>>
Get a mutable reference to an entry in the map
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let class = DashMap::new();
class.insert("Albin", 15);
*class.get_mut("Albin").unwrap() -= 1;
assert_eq!(*class.get("Albin").unwrap(), 14);
pub fn try_get<Q>(&'a self, key: &Q) -> TryResult<Ref<'a, K, V>>
pub fn try_get<Q>(&'a self, key: &Q) -> TryResult<Ref<'a, K, V>>
Get an immutable reference to an entry in the map, if the shard is not locked. If the shard is locked, the function will return [TryResult::Locked].
§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;
let map = DashMap::new();
map.insert("Johnny", 21);
assert_eq!(*map.try_get("Johnny").unwrap(), 21);
let _result1_locking = map.get_mut("Johnny");
let result2 = map.try_get("Johnny");
assert!(result2.is_locked());
pub fn try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V>>
pub fn try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V>>
Get a mutable reference to an entry in the map, if the shard is not locked. If the shard is locked, the function will return [TryResult::Locked].
§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;
let map = DashMap::new();
map.insert("Johnny", 21);
*map.try_get_mut("Johnny").unwrap() += 1;
assert_eq!(*map.get("Johnny").unwrap(), 22);
let _result1_locking = map.get("Johnny");
let result2 = map.try_get_mut("Johnny");
assert!(result2.is_locked());
pub fn shrink_to_fit(&self)
pub fn shrink_to_fit(&self)
Remove excess capacity to reduce memory usage.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;
let map = DashMap::new();
map.insert("Johnny", 21);
assert!(map.capacity() > 0);
map.remove("Johnny");
map.shrink_to_fit();
assert_eq!(map.capacity(), 0);
pub fn retain(&self, f: impl FnMut(&K, &mut V) -> bool)
pub fn retain(&self, f: impl FnMut(&K, &mut V) -> bool)
Retain elements that whose predicates return true and discard elements whose predicates return false.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let people = DashMap::new();
people.insert("Albin", 15);
people.insert("Jones", 22);
people.insert("Charlie", 27);
people.retain(|_, v| *v > 20);
assert_eq!(people.len(), 2);
pub fn len(&self) -> usize
pub fn len(&self) -> usize
Fetches the total number of key-value pairs stored in the map.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let people = DashMap::new();
people.insert("Albin", 15);
people.insert("Jones", 22);
people.insert("Charlie", 27);
assert_eq!(people.len(), 3);
pub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the map is empty or not.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let map = DashMap::<(), ()>::new();
assert!(map.is_empty());
pub fn clear(&self)
pub fn clear(&self)
Removes all key-value pairs in the map.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let stats = DashMap::new();
stats.insert("Goals", 4);
assert!(!stats.is_empty());
stats.clear();
assert!(stats.is_empty());
pub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns how many key-value pairs the map can store without reallocating.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
pub fn alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
pub fn alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
Modify a specific value according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let stats = DashMap::new();
stats.insert("Goals", 4);
stats.alter("Goals", |_, v| v * 2);
assert_eq!(*stats.get("Goals").unwrap(), 8);
§Panics
If the given closure panics, then alter
will abort the process
pub fn alter_all(&self, f: impl FnMut(&K, V) -> V)
pub fn alter_all(&self, f: impl FnMut(&K, V) -> V)
Modify every value in the map according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let stats = DashMap::new();
stats.insert("Wins", 4);
stats.insert("Losses", 2);
stats.alter_all(|_, v| v + 1);
assert_eq!(*stats.get("Wins").unwrap(), 5);
assert_eq!(*stats.get("Losses").unwrap(), 3);
§Panics
If the given closure panics, then alter_all
will abort the process
pub fn view<Q, R>(&self, key: &Q, f: impl FnOnce(&K, &V) -> R) -> Option<R>
pub fn view<Q, R>(&self, key: &Q, f: impl FnOnce(&K, &V) -> R) -> Option<R>
Scoped access into an item of the map according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let warehouse = DashMap::new();
warehouse.insert(4267, ("Banana", 100));
warehouse.insert(2359, ("Pear", 120));
let fruit = warehouse.view(&4267, |_k, v| *v);
assert_eq!(fruit, Some(("Banana", 100)));
§Panics
If the given closure panics, then view
will abort the process
pub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Checks if the map contains a specific key.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let team_sizes = DashMap::new();
team_sizes.insert("Dakota Cherries", 23);
assert!(team_sizes.contains_key("Dakota Cherries"));
pub fn entry(&'a self, key: K) -> Entry<'a, K, V>
pub fn entry(&'a self, key: K) -> Entry<'a, K, V>
Advanced entry API that tries to mimic std::collections::HashMap
.
See the documentation on dashmap::mapref::entry
for more details.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
pub fn try_entry(&'a self, key: K) -> Option<Entry<'a, K, V>>
pub fn try_entry(&'a self, key: K) -> Option<Entry<'a, K, V>>
Advanced entry API that tries to mimic std::collections::HashMap
.
See the documentation on dashmap::mapref::entry
for more details.
Returns None if the shard is currently locked.
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Advanced entry API that tries to mimic std::collections::HashMap::try_reserve
.
Tries to reserve capacity for at least shard * additional
and may reserve more space to avoid frequent reallocations.
§Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Trait Implementations§
§impl Clone for Components
impl Clone for Components
§fn clone(&self) -> Components
fn clone(&self) -> Components
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for Components
impl Debug for Components
§impl Default for Components
impl Default for Components
§fn default() -> Components
fn default() -> Components
§impl Deref for Components
impl Deref for Components
§impl DerefMut for Components
impl DerefMut for Components
§fn deref_mut(&mut self) -> &mut <Components as Deref>::Target
fn deref_mut(&mut self) -> &mut <Components as Deref>::Target
§impl<'de> Deserialize<'de> for Components
impl<'de> Deserialize<'de> for Components
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Components, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Components, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl From<&Components> for Vec<Component>
impl From<&Components> for Vec<Component>
§fn from(tys: &Components) -> Vec<Component>
fn from(tys: &Components) -> Vec<Component>
§impl From<&DashMap<ComponentTypeId, Component>> for Components
impl From<&DashMap<ComponentTypeId, Component>> for Components
§fn from(components: &DashMap<ComponentTypeId, Component>) -> Components
fn from(components: &DashMap<ComponentTypeId, Component>) -> Components
§impl From<Components> for DashMap<ComponentTypeId, Component>
impl From<Components> for DashMap<ComponentTypeId, Component>
§fn from(tys: Components) -> DashMap<ComponentTypeId, Component>
fn from(tys: Components) -> DashMap<ComponentTypeId, Component>
§impl From<Components> for Vec<Component>
impl From<Components> for Vec<Component>
§fn from(tys: Components) -> Vec<Component>
fn from(tys: Components) -> Vec<Component>
§impl From<DashMap<ComponentTypeId, Component>> for Components
impl From<DashMap<ComponentTypeId, Component>> for Components
§fn from(components: DashMap<ComponentTypeId, Component>) -> Components
fn from(components: DashMap<ComponentTypeId, Component>) -> Components
§impl From<Vec<Component>> for Components
impl From<Vec<Component>> for Components
§fn from(components: Vec<Component>) -> Components
fn from(components: Vec<Component>) -> Components
§impl FromIterator<Component> for Components
impl FromIterator<Component> for Components
§fn from_iter<I>(iter: I) -> Componentswhere
I: IntoIterator<Item = Component>,
fn from_iter<I>(iter: I) -> Componentswhere
I: IntoIterator<Item = Component>,
§impl Hash for Components
impl Hash for Components
§impl IntoIterator for Components
impl IntoIterator for Components
§type IntoIter = OwningIter<ComponentTypeId, Component>
type IntoIter = OwningIter<ComponentTypeId, Component>
§fn into_iter(self) -> <Components as IntoIterator>::IntoIter
fn into_iter(self) -> <Components as IntoIterator>::IntoIter
§impl JsonSchema for Components
impl JsonSchema for Components
§fn schema_name() -> Cow<'static, str>
fn schema_name() -> Cow<'static, str>
§fn json_schema(schema_generator: &mut SchemaGenerator) -> Schema
fn json_schema(schema_generator: &mut SchemaGenerator) -> Schema
§fn always_inline_schema() -> bool
fn always_inline_schema() -> bool
inline_schema()
insteadinline_schema()
instead“. Read more§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref
keyword. Read more§impl NamespacedTypeContainer for Components
impl NamespacedTypeContainer for Components
type TypeId = ComponentTypeId
type TypeIds = ComponentTypeIds
type Type = Component
fn new() -> Components
fn push<C>(&self, component: C)where
C: Into<Component>,
fn type_ids(&self) -> Self::TypeIds
fn types(&self) -> DashSet<Self::Type>
fn to_vec(&self) -> Vec<Self::Type>
fn namespaces(&self) -> DashSet<String>
fn get_by_namespace(&self, namespace: &str) -> Self
fn get_types_by_namespace(&self, namespace: &str) -> Self::TypeIds
fn find_by_type_name(&self, search: &str) -> Self
fn count_by_namespace(&self, namespace: &str) -> usize
§impl PartialEq for Components
impl PartialEq for Components
§impl Serialize for Components
impl Serialize for Components
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for Components
Auto Trait Implementations§
impl Freeze for Components
impl !RefUnwindSafe for Components
impl Send for Components
impl Sync for Components
impl Unpin for Components
impl UnwindSafe for Components
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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