### hasher() example: get reference to BuildHasher Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap and obtains a reference to its `BuildHasher` (RandomState) using `hasher()`. ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let hasher = RandomState::new(); let map: DashMap = DashMap::new(); let hasher: &RandomState = map.hasher(); ``` -------------------------------- ### Create a DashMap with with_capacity() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a specified starting capacity and inserts two entries. ```rust use dashmap::DashMap; let mappings = DashMap::with_capacity(2); mappings.insert(2, 4); mappings.insert(8, 16); ``` -------------------------------- ### Create a DashMap with with_capacity_and_hasher() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a specified starting capacity and hasher, then inserts two entries. ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mappings = DashMap::with_capacity_and_hasher(2, s); mappings.insert(2, 4); mappings.insert(8, 16); ``` -------------------------------- ### with_capacity_and_hasher(capacity: usize, hasher: S) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a specified starting capacity and hasher. ```APIDOC ## with_capacity_and_hasher(capacity: usize, hasher: S) ### Description Creates a new DashMap with a specified starting capacity and hasher. ### Method with_capacity_and_hasher ### Parameters - **capacity** (usize) - Required - The initial capacity of the map. - **hasher** (S) - Required - The hasher to use for hashing keys. ### Request Example ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mappings = DashMap::with_capacity_and_hasher(2, s); mappings.insert(2, 4); mappings.insert(8, 16); ``` ### Response Returns a new DashMap instance with the specified capacity and hasher. ``` -------------------------------- ### Create a DashSet with capacity Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Creates a new DashSet with a specified starting capacity. ```rust use dashmap::DashSet; let numbers = DashSet::with_capacity(2); numbers.insert(2); numbers.insert(8); ``` -------------------------------- ### DashSet::with_capacity Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Creates a new DashSet with a specified starting capacity. ```APIDOC ## with_capacity ### Description Creates a new DashSet with a specified starting capacity. ### Method with_capacity ### Parameters - **capacity** (usize) - Required - The initial capacity of the set. ### Request Example ```rust use dashmap::DashSet; let numbers = DashSet::with_capacity(2); numbers.insert(2); numbers.insert(8); ``` ### Response #### Success Response - **Self** - A new DashSet instance with the specified capacity. #### Response Example ```rust let numbers = DashSet::with_capacity(2); ``` ``` -------------------------------- ### DashSet::with_capacity_and_hasher Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Creates a new DashSet with a specified starting capacity and hasher. ```APIDOC ## with_capacity_and_hasher ### Description Creates a new DashSet with a specified starting capacity and hasher. ### Method with_capacity_and_hasher ### Parameters - **capacity** (usize) - Required - The initial capacity of the set. - **hasher** (S) - Required - The hasher to use for hashing keys. ### Request Example ```rust use dashmap::DashSet; use std::collections::hash_map::RandomState; let s = RandomState::new(); let numbers = DashSet::with_capacity_and_hasher(2, s); numbers.insert(2); numbers.insert(8); ``` ### Response #### Success Response - **Self** - A new DashSet instance with the specified capacity and hasher. #### Response Example ```rust let s = RandomState::new(); let numbers = DashSet::with_capacity_and_hasher(2, s); ``` ``` -------------------------------- ### Create a DashSet with capacity and hasher Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Creates a new DashSet with a specified starting capacity and hasher. ```rust use dashmap::DashSet; use std::collections::hash_map::RandomState; let s = RandomState::new(); let numbers = DashSet::with_capacity_and_hasher(2, s); numbers.insert(2); numbers.insert(8); ``` -------------------------------- ### with_capacity(capacity: usize) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a specified starting capacity. ```APIDOC ## with_capacity(capacity: usize) ### Description Creates a new DashMap with a specified starting capacity. ### Method with_capacity ### Parameters - **capacity** (usize) - Required - The initial capacity of the map. ### Request Example ```rust use dashmap::DashMap; let mappings = DashMap::with_capacity(2); mappings.insert(2, 4); mappings.insert(8, 16); ``` ### Response Returns a new DashMap instance with the specified capacity. ``` -------------------------------- ### with_capacity_and_hasher_and_shard_amount(capacity: usize, hasher: S, shard_amount: usize) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a specified starting capacity, hasher, and shard amount. ```APIDOC ## with_capacity_and_hasher_and_shard_amount(capacity: usize, hasher: S, shard_amount: usize) ### Description Creates a new DashMap with a specified starting capacity, hasher, and shard amount. The shard amount must be greater than 0 and a power of two; otherwise, the function will panic. ### Method with_capacity_and_hasher_and_shard_amount ### Parameters - **capacity** (usize) - Required - The initial capacity of the map. - **hasher** (S) - Required - The hasher to use for hashing keys. - **shard_amount** (usize) - Required - The number of shards to use. Must be greater than 0 and a power of two. ### Request Example ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mappings = DashMap::with_capacity_and_hasher_and_shard_amount(2, s, 32); mappings.insert(2, 4); mappings.insert(8, 16); ``` ### Response Returns a new DashMap instance with the specified capacity, hasher, and shard amount. ``` -------------------------------- ### Example: Using shards() on a ReadOnlyView Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.ReadOnlyView.html Requires the `raw-api` feature to be enabled. Creates a DashMap, converts it to a read-only view with into_read_only(), and prints the number of shards. ```rust use dashmap::DashMap; let map = DashMap::<(), ()>::new().into_read_only(); println!("Amount of shards: {}", map.shards().len()); ``` -------------------------------- ### Example: iterating over a DashMap Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.Iter.html Creates a DashMap, inserts a key-value pair, and asserts that iter().count() returns 1. ```rust use dashmap::DashMap; let map = DashMap::new(); map.insert("hello", "world"); assert_eq!(map.iter().count(), 1); ``` -------------------------------- ### Create a DashMap with with_capacity_and_hasher_and_shard_amount() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a specified starting capacity, hasher, and shard amount. The shard amount must be greater than 0 and a power of two; otherwise the function panics. ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mappings = DashMap::with_capacity_and_hasher_and_shard_amount(2, s, 32); mappings.insert(2, 4); mappings.insert(8, 16); ``` -------------------------------- ### DashSet::get Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Get a reference to an entry in the set. ```APIDOC ## get ### Description Get a reference to an entry in the set. ### Method get ### Parameters - **key** (&Q) - Required - The key to look up. ### Request Example ```rust use dashmap::DashSet; let youtubers = DashSet::new(); youtubers.insert("Bosnian Bill"); assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), "Bosnian Bill"); ``` ### Response #### Success Response - **Option>** - A reference to the entry if it exists, `None` otherwise. #### Response Example ```rust let youtubers = DashSet::new(); youtubers.insert("Bosnian Bill"); let entry = youtubers.get("Bosnian Bill"); ``` ``` -------------------------------- ### Iter::step_by Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.Iter.html Creates an iterator starting at the same point, but stepping by the given amount at each iteration. This is a standard iterator adapter. ```APIDOC ## Iter::step_by ### Description Creates an iterator starting at the same point, but stepping by the given amount at each iteration. This is a standard iterator adapter. ### Method `fn step_by(self, step: usize) -> StepBy` ### Parameters - `self` (consumed) - The iterator instance. - `step` (usize) - The step size between elements. ### Returns - `StepBy` - An iterator that steps by the given amount. ### Example ```rust use dashmap::DashMap; let map = DashMap::new(); map.insert("hello", "world"); let iter = map.iter().step_by(1); assert_eq!(iter.count(), 1); ``` ``` -------------------------------- ### shards() example: print number of shards Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Requires the `raw-api` feature. Creates a new DashMap and prints the number of shards using `shards().len()`. ```rust use dashmap::DashMap; let map = DashMap::<(), ()>::new(); println!("Amount of shards: {}", map.shards().len()); ``` -------------------------------- ### OwningIter::step_by Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.OwningIter.html Creates an iterator starting at the same point, but stepping by the given amount at each iteration. ```APIDOC ## OwningIter::step_by ### Description Creates an iterator starting at the same point, but stepping by the given amount at each iteration. ### Method `fn step_by(self, step: usize) -> StepBy` ### Parameters - `self` (owned) - The iterator instance. - `step` (usize) - The step size. ### Returns - `StepBy` - An iterator that steps by the given amount. ``` -------------------------------- ### get Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.ReadOnlyView.html Returns a reference to the value corresponding to the key. ```APIDOC ## get ### Description Returns a reference to the value corresponding to the key. ### Method get ### Signature `pub fn get(&'a self, key: &Q) -> Option<&'a V> where K: Borrow, Q: Hash + Eq + ?Sized` ### Parameters - `key` (`&Q`) - The key to look up. ### Returns - `Option<&'a V>` - A reference to the value if found, otherwise `None`. ``` -------------------------------- ### insert() example: insert key-value pair Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Inserts a key and value into a DashMap. May deadlock if called while holding any reference into the map. ```rust use dashmap::DashMap; let map = DashMap::new(); map.insert("I am the key!", "And I am the value!"); ``` -------------------------------- ### Get reference from DashSet Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Retrieves a reference to an entry in the set. ```rust use dashmap::DashSet; let youtubers = DashSet::new(); youtubers.insert("Bosnian Bill"); assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), "Bosnian Bill"); ``` -------------------------------- ### determine_map() example: find shard for a key Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Requires the `raw-api` feature. Creates a map, inserts a key, and prints the shard index for that key using `determine_map`. ```rust use dashmap::DashMap; let map = DashMap::new(); map.insert("coca-cola", 1.4); println!("coca-cola is stored in shard: {}", map.determine_map("coca-cola")); ``` -------------------------------- ### shards_mut() example: insert into a specific shard Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Requires the `raw-api` feature. Demonstrates using `shards_mut()` to insert a key-value pair into a specific shard, using a custom hasher and `determine_map` to find the shard index. ```rust use dashmap::DashMap; use dashmap::SharedValue; use std::hash::{Hash, Hasher, BuildHasher}; let mut map = DashMap::::new(); let shard_ind = map.determine_map(&42); let mut factory = map.hasher().clone(); let hasher = |tuple: &(i32, SharedValue<&'static str>)| { let mut hasher = factory.build_hasher(); tuple.0.hash(&mut hasher); hasher.finish() }; let data = (42, SharedValue::new("forty two")); let hash = hasher(&data); map.shards_mut()[shard_ind].get_mut().insert(hash, data, hasher); assert_eq!(*map.get(&42).unwrap(), "forty two"); ``` -------------------------------- ### determine_shard() example: find shard for a hash Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Requires the `raw-api` feature. Computes a hash for a key using `hash_usize` and prints the shard index for that hash using `determine_shard`. ```rust use dashmap::DashMap; let map: DashMap = DashMap::new(); let key = "key"; let hash = map.hash_usize(&key); println!("hash is stored in shard: {}", map.determine_shard(hash)); ``` -------------------------------- ### Collect key-value pairs from DashMap using into_iter Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.OwningIter.html Example from the documentation showing how to create a DashMap, insert two entries, and collect the key-value pairs into a Vec using into_iter(). The resulting vector has a length of 2. ```rust use dashmap::DashMap; let map = DashMap::new(); map.insert("hello", "world"); map.insert("alex", "steve"); let pairs: Vec<(&'static str, &'static str)> = map.into_iter().collect(); assert_eq!(pairs.len(), 2); ``` -------------------------------- ### remove() example: remove entry and assert value Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Removes an entry from the map, returning the key and value. May deadlock if called while holding any reference into the map. ```rust use dashmap::DashMap; let soccer_team = DashMap::new(); soccer_team.insert("Jack", "Goalie"); assert_eq!(soccer_team.remove("Jack").unwrap().1, "Goalie"); ``` -------------------------------- ### new Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Creates a new unlocked RwLock instance. ```APIDOC ## new ### Description Creates a new instance of an `RwLock` which is unlocked. ### Signature `pub const fn new(val: T) -> RwLock` ### Parameters - `val (T)` - The initial value to store in the lock. ### Returns A new `RwLock` instance. ``` -------------------------------- ### get Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Get an immutable reference to an entry in the map. May deadlock if called when holding a mutable reference into the map. ```APIDOC ## get(key) ### Description Get an immutable reference to an entry in the map. ### Method get ### Signature pub fn get(&'a self, key: &Q) -> Option> where K: Borrow, Q: Hash + Eq + ?Sized, ### Parameters - **key** (&Q) - Required - The key to look up. ### Locking Behaviour May deadlock if called when holding a mutable reference into the map. ### Example ```rust use dashmap::DashMap; let youtubers = DashMap::new(); youtubers.insert("Bosnian Bill", 457000); assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), 457000); ``` ``` -------------------------------- ### Get immutable reference with get Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Retrieves an immutable reference to an entry. May deadlock if called while holding a mutable reference. ```rust use dashmap::DashMap; let youtubers = DashMap::new(); youtubers.insert("Bosnian Bill", 457000); assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), 457000); ``` -------------------------------- ### Try to get mutable reference with try_get_mut Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Attempts to get a mutable reference without blocking. Returns TryResult::Locked if the shard is currently locked. ```rust 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()); ``` -------------------------------- ### Try to get immutable reference with try_get Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Attempts to get an immutable reference without blocking. Returns TryResult::Locked if the shard is currently locked. ```rust 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()); ``` -------------------------------- ### remove_if() examples: conditional removal (false and true conditions) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Two examples showing `remove_if` with a condition that returns false (entry remains) and true (entry removed). May deadlock if called while holding any reference into the map. ```rust 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")); ``` ```rust 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")); ``` -------------------------------- ### Create a DashMap with with_hasher() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a capacity of 0 and a provided hasher, then inserts a key-value pair. ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let reviews = DashMap::with_hasher(s); reviews.insert("Veloren", "What a fantastic game!"); ``` -------------------------------- ### Create a DashMap with with_capacity_and_shard_amount() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a specified capacity and shard amount. The shard amount must be greater than 0 and a power of two; otherwise the function panics. ```rust use dashmap::DashMap; let mappings = DashMap::with_capacity_and_shard_amount(32, 32); mappings.insert(2, 4); mappings.insert(8, 16); ``` -------------------------------- ### Create a DashMap with with_hasher_and_shard_amount() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a specified hasher and shard amount. The shard amount must be greater than 0 and a power of two; otherwise the function panics. ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mappings = DashMap::with_hasher_and_shard_amount(s, 32); mappings.insert(2, 4); mappings.insert(8, 16); ``` -------------------------------- ### Get DashSet length Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Use len to retrieve the total number of elements currently stored in the set. ```rust use dashmap::DashSet; let people = DashSet::new(); people.insert("Albin"); people.insert("Jones"); people.insert("Charlie"); assert_eq!(people.len(), 3); ``` -------------------------------- ### new() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a capacity of 0. ```APIDOC ## new() ### Description Creates a new DashMap with a capacity of 0. ### Method new ### Parameters None ### Request Example ```rust use dashmap::DashMap; let reviews = DashMap::new(); reviews.insert("Veloren", "What a fantastic game!"); ``` ### Response Returns a new DashMap instance. ``` -------------------------------- ### get_mut Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Get a mutable reference to an entry in the map. May deadlock if called when holding any sort of reference into the map. ```APIDOC ## get_mut(key) ### Description Get a mutable reference to an entry in the map. ### Method get_mut ### Signature pub fn get_mut(&'a self, key: &Q) -> Option> where K: Borrow, Q: Hash + Eq + ?Sized, ### Parameters - **key** (&Q) - Required - The key to look up. ### Locking Behaviour May deadlock if called when holding any sort of reference into the map. ### Example ```rust use dashmap::DashMap; let class = DashMap::new(); class.insert("Albin", 15); *class.get_mut("Albin").unwrap() -= 1; assert_eq!(*class.get("Albin").unwrap(), 14); ``` ``` -------------------------------- ### try_upgradable_read_until Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Attempts to acquire this RwLock with upgradable read access until a specific instant is reached. ```APIDOC ## try_upgradable_read_until ### Description Attempts to acquire this `RwLock` with upgradable read access until a timeout is reached. If the access could not be granted before the timeout expires, then `None` is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped. ### Signature `pub fn try_upgradable_read_until(&self, timeout: ::Instant) -> Option>` ### Parameters - `timeout` (`::Instant`): The absolute time to wait until for the lock. ### Returns - `Option>`: The guard if acquired, `None` if timed out. ``` -------------------------------- ### Create a DashMap with with_shard_amount() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a specified shard amount. The shard amount must be greater than 0 and a power of two; otherwise the function panics. ```rust use dashmap::DashMap; let mappings = DashMap::with_shard_amount(32); mappings.insert(2, 4); mappings.insert(8, 16); ``` -------------------------------- ### try_get_mut Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html 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. ```APIDOC ## try_get_mut(key) ### Description 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. ### Method try_get_mut ### Signature pub fn try_get_mut(&'a self, key: &Q) -> TryResult> where K: Borrow, Q: Hash + Eq + ?Sized, ### Parameters - **key** (&Q) - Required - The key to look up. ### Example ```rust 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()); ``` ``` -------------------------------- ### try_upgradable_read Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Attempts to acquire this RwLock with upgradable read access. Returns None if the access could not be granted immediately. ```APIDOC ## try_upgradable_read ### Description Attempts to acquire this `RwLock` with upgradable read access. If the access could not be granted at this time, then `None` is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped. This function does not block. ### Signature `pub fn try_upgradable_read(&self) -> Option>` ### Returns - `Option>`: The guard if acquired, `None` otherwise. ``` -------------------------------- ### try_get Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html 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. ```APIDOC ## try_get(key) ### Description 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. ### Method try_get ### Signature pub fn try_get(&'a self, key: &Q) -> TryResult> where K: Borrow, Q: Hash + Eq + ?Sized, ### Parameters - **key** (&Q) - Required - The key to look up. ### Example ```rust 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()); ``` ``` -------------------------------- ### Get mutable reference with get_mut Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Retrieves a mutable reference to an entry. May deadlock if called while holding any reference into the map. ```rust use dashmap::DashMap; let class = DashMap::new(); class.insert("Albin", 15); *class.get_mut("Albin").unwrap() -= 1; assert_eq!(*class.get("Albin").unwrap(), 14); ``` -------------------------------- ### with_capacity_and_shard_amount(capacity: usize, shard_amount: usize) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a specified capacity and shard amount. ```APIDOC ## with_capacity_and_shard_amount(capacity: usize, shard_amount: usize) ### Description Creates a new DashMap with a specified capacity and shard amount. The shard amount must be greater than 0 and a power of two; otherwise, the function will panic. ### Method with_capacity_and_shard_amount ### Parameters - **capacity** (usize) - Required - The initial capacity of the map. - **shard_amount** (usize) - Required - The number of shards to use. Must be greater than 0 and a power of two. ### Request Example ```rust use dashmap::DashMap; let mappings = DashMap::with_capacity_and_shard_amount(32, 32); mappings.insert(2, 4); mappings.insert(8, 16); ``` ### Response Returns a new DashMap instance with the specified capacity and shard amount. ``` -------------------------------- ### Get map length with len Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Returns the total number of key-value pairs. May deadlock if called while holding a mutable reference. ```rust use dashmap::DashMap; let people = DashMap::new(); people.insert("Albin", 15); people.insert("Jones", 22); people.insert("Charlie", 27); assert_eq!(people.len(), 3); ``` -------------------------------- ### take Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.IterMut.html Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ```APIDOC ## take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Method take ### Signature ```rust fn take(self, n: usize) -> Take where Self: Sized, ``` ### Parameters - **n** (usize) - Required - The number of elements to take. ### Return Value - **Take** - An iterator adapter that yields at most `n` elements. ``` -------------------------------- ### Create a DashMap with new() Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a DashMap with a capacity of 0 and inserts a key-value pair. ```rust use dashmap::DashMap; let reviews = DashMap::new(); reviews.insert("Veloren", "What a fantastic game!"); ``` -------------------------------- ### from_raw Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Creates a new RwLock from a raw lock and value. ```APIDOC ## from_raw ### Description Creates a new instance of an `RwLock` based on a pre-existing `RawRwLock`. ### Signature `pub const fn from_raw(raw_rwlock: R, val: T) -> RwLock` ### Parameters - `raw_rwlock` (`R`): The raw lock instance. - `val` (`T`): The initial value. ### Returns - `RwLock`: The newly created lock. ``` -------------------------------- ### with_hasher_and_shard_amount(hasher: S, shard_amount: usize) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a specified hasher and shard amount. ```APIDOC ## with_hasher_and_shard_amount(hasher: S, shard_amount: usize) ### Description Creates a new DashMap with a specified hasher and shard amount. The shard amount must be greater than 0 and a power of two; otherwise, the function will panic. ### Method with_hasher_and_shard_amount ### Parameters - **hasher** (S) - Required - The hasher to use for hashing keys. - **shard_amount** (usize) - Required - The number of shards to use. Must be greater than 0 and a power of two. ### Request Example ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mappings = DashMap::with_hasher_and_shard_amount(s, 32); mappings.insert(2, 4); mappings.insert(8, 16); ``` ### Response Returns a new DashMap instance with the specified hasher and shard amount. ``` -------------------------------- ### with_hasher(hasher: S) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a capacity of 0 and the provided hasher. ```APIDOC ## with_hasher(hasher: S) ### Description Creates a new DashMap with a capacity of 0 and the provided hasher. ### Method with_hasher ### Parameters - **hasher** (S) - Required - The hasher to use for hashing keys. ### Request Example ```rust use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let reviews = DashMap::with_hasher(s); reviews.insert("Veloren", "What a fantastic game!"); ``` ### Response Returns a new DashMap instance with the specified hasher. ``` -------------------------------- ### into_inner Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Consumes the RwLock and returns the underlying data. ```APIDOC ## into_inner ### Description Consumes this `RwLock`, returning the underlying data. ### Signature `pub fn into_inner(self) -> T` ### Returns The underlying value of the lock. ``` -------------------------------- ### DashSet::new Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Creates a new DashSet with a capacity of 0. ```APIDOC ## new ### Description Creates a new DashSet with a capacity of 0. ### Method new ### Parameters None ### Request Example ```rust use dashmap::DashSet; let games = DashSet::new(); games.insert("Veloren"); ``` ### Response #### Success Response - **Self** - A new DashSet instance. #### Response Example ```rust let games = DashSet::new(); ``` ``` -------------------------------- ### take_any Source: https://docs.rs/dashmap/6.2.1/dashmap/rayon/map/struct.IterMut.html Creates an iterator that yields n elements from anywhere in the original iterator. ```APIDOC ## take_any ### Description Creates an iterator that yields `n` elements from _anywhere_ in the original iterator. ### Method take_any ### Signature ```rust fn take_any(self, n: usize) -> TakeAny ``` ### Parameters - `n` (usize) - Required - The number of elements to yield. ### Returns - `TakeAny` - An iterator that yields `n` elements from anywhere in the original iterator. ``` -------------------------------- ### force_unlock_write Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Forcibly unlocks a write lock. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockWriteGuard` object alive, for example when dealing with FFI. ```APIDOC ## force_unlock_write ### Description Forcibly unlocks a write lock. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockWriteGuard` object alive, for example when dealing with FFI. ### Method unsafe fn ### Signature `pub unsafe fn force_unlock_write(&self)` ### Safety This method must only be called if the current thread logically owns a `RwLockWriteGuard` but that guard has be discarded using `mem::forget`. Behavior is undefined if a rwlock is write-unlocked when not write-locked. ``` -------------------------------- ### partition Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.IterMut.html Consumes an iterator, creating two collections from it. ```APIDOC ## partition ### Description Consumes an iterator, creating two collections from it. ### Method partition ### Signature ```rust fn partition(self, f: F) -> (B, B) where Self: Sized, B: Default + Extend, F: FnMut(&Self::Item) -> bool, ``` ### Parameters - **f** (F) - Required - A closure that takes a reference to an item and returns a boolean indicating which collection the item belongs to. ### Return Value - **(B, B)** - A tuple of two collections: the first contains items for which `f` returned `true`, the second contains the rest. ``` -------------------------------- ### force_unlock_read Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Forcibly unlocks a read lock. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockReadGuard` object alive, for example when dealing with FFI. ```APIDOC ## force_unlock_read ### Description Forcibly unlocks a read lock. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockReadGuard` object alive, for example when dealing with FFI. ### Method unsafe fn ### Signature `pub unsafe fn force_unlock_read(&self)` ### Safety This method must only be called if the current thread logically owns a `RwLockReadGuard` but that guard has be discarded using `mem::forget`. Behavior is undefined if a rwlock is read-unlocked when not read-locked. ``` -------------------------------- ### try_upgradable_read_for Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Attempts to acquire this RwLock with upgradable read access until a timeout is reached. ```APIDOC ## try_upgradable_read_for ### Description Attempts to acquire this `RwLock` with upgradable read access until a timeout is reached. If the access could not be granted before the timeout expires, then `None` is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped. ### Signature `pub fn try_upgradable_read_for(&self, timeout: ::Duration) -> Option>` ### Parameters - `timeout` (`::Duration`): The maximum duration to wait for the lock. ### Returns - `Option>`: The guard if acquired within the timeout, `None` if timed out. ``` -------------------------------- ### data_ptr Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Returns a raw pointer to the underlying data. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockReadGuard` or `RwLockWriteGuard` object alive, for example when dealing with FFI. ```APIDOC ## data_ptr ### Description Returns a raw pointer to the underlying data. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockReadGuard` or `RwLockWriteGuard` object alive, for example when dealing with FFI. ### Method fn ### Signature `pub fn data_ptr(&self) -> *mut T` ### Safety You must ensure that there are no data races when dereferencing the returned pointer, for example if the current thread logically owns a `RwLockReadGuard` or `RwLockWriteGuard` but that guard has been discarded using `mem::forget`. ``` -------------------------------- ### OwningIter::next Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.OwningIter.html Advances the iterator and returns the next key-value pair as an Option<(K, V)>. ```APIDOC ## OwningIter::next ### Description Advances the iterator and returns the next value. ### Method `fn next(&mut self) -> Option` ### Parameters - `self` (mutable reference) - The iterator instance. ### Returns - `Option<(K, V)>` - The next key-value pair, or `None` if iteration is complete. ### Example ```rust use dashmap::DashMap; let map = DashMap::new(); map.insert("hello", "world"); map.insert("alex", "steve"); let mut iter = map.into_iter(); while let Some((k, v)) = iter.next() { println!("{}: {}", k, v); } ``` ``` -------------------------------- ### with_shard_amount(shard_amount: usize) Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Creates a new DashMap with a specified shard amount. ```APIDOC ## with_shard_amount(shard_amount: usize) ### Description Creates a new DashMap with a specified shard amount. The shard amount must be greater than 0 and a power of two; otherwise, the function will panic. ### Method with_shard_amount ### Parameters - **shard_amount** (usize) - Required - The number of shards to use. Must be greater than 0 and a power of two. ### Request Example ```rust use dashmap::DashMap; let mappings = DashMap::with_shard_amount(32); mappings.insert(2, 4); mappings.insert(8, 16); ``` ### Response Returns a new DashMap instance with the specified shard amount. ``` -------------------------------- ### Iterating and mutating values with iter_mut Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.IterMut.html Example usage of iter_mut() to iterate over a DashMap and mutate each value. It inserts a key-value pair, increments the value by 1 using for_each, and asserts the updated value is 22. ```rust 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); ``` -------------------------------- ### Create a DashSet with a hasher Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Creates a new DashSet with a capacity of 0 and the provided hasher. ```rust use dashmap::DashSet; use std::collections::hash_map::RandomState; let s = RandomState::new(); let games = DashSet::with_hasher(s); games.insert("Veloren"); ``` -------------------------------- ### force_unlock_write_fair Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Forcibly unlocks a write lock using a fair unlock protocol. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockWriteGuard` object alive, for example when dealing with FFI. ```APIDOC ## force_unlock_write_fair ### Description Forcibly unlocks a write lock using a fair unlock protocol. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockWriteGuard` object alive, for example when dealing with FFI. ### Method unsafe fn ### Signature `pub unsafe fn force_unlock_write_fair(&self)` ### Safety This method must only be called if the current thread logically owns a `RwLockWriteGuard` but that guard has be discarded using `mem::forget`. Behavior is undefined if a rwlock is write-unlocked when not write-locked. ``` -------------------------------- ### force_unlock_read_fair Source: https://docs.rs/dashmap/6.2.1/dashmap/type.RwLock.html Forcibly unlocks a read lock using a fair unlock protocol. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockReadGuard` object alive, for example when dealing with FFI. ```APIDOC ## force_unlock_read_fair ### Description Forcibly unlocks a read lock using a fair unlock protocol. This is useful when combined with `mem::forget` to hold a lock without the need to maintain a `RwLockReadGuard` object alive, for example when dealing with FFI. ### Method unsafe fn ### Signature `pub unsafe fn force_unlock_read_fair(&self)` ### Safety This method must only be called if the current thread logically owns a `RwLockReadGuard` but that guard has be discarded using `mem::forget`. Behavior is undefined if a rwlock is read-unlocked when not read-locked. ``` -------------------------------- ### entry Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Advanced entry API that tries to mimic `std::collections::HashMap`. ```APIDOC ## entry ### Description Advanced entry API that tries to mimic `std::collections::HashMap`. See the documentation on `dashmap::mapref::entry` for more details. ### Method N/A ### Endpoint N/A ### Parameters #### Function Parameters - **key** (`K`) - Required - The key to get an entry for. ### Request Example ```rust // No example provided in source ``` ### Response #### Success Response - Returns `Entry<'a, K, V>` - The entry for the given key. #### Response Example ```rust // No example provided in source ``` ### Errors - **Locking**: May deadlock if called when holding any sort of reference into the map. ``` -------------------------------- ### by_ref Source: https://docs.rs/dashmap/6.2.1/dashmap/iter/struct.IterMut.html Creates a “by reference” adapter for this instance of `Iterator`. ```APIDOC ## by_ref ### Description Creates a “by reference” adapter for this instance of `Iterator`. ### Method by_ref ### Signature ```rust fn by_ref(&mut self) -> &mut Self where Self: Sized, ``` ### Return Value - **&mut Self** - A mutable reference to the iterator, allowing it to be consumed partially. ``` -------------------------------- ### into_shards Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashMap.html Consumes this `DashMap` and returns the inner shards. You should probably not use this unless you know what you are doing. Requires the `raw-api` feature to be enabled. See `DashMap::shards()` and `DashMap::shards_mut()` for more information. ```APIDOC ## into_shards ### Description Consumes this `DashMap` and returns the inner shards. You should probably not use this unless you know what you are doing. Requires the `raw-api` feature to be enabled. See `DashMap::shards()` and `DashMap::shards_mut()` for more information. ### Method into_shards ### Parameters None ### Response Returns the inner shards as a boxed slice. ``` -------------------------------- ### Create a new DashSet Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.DashSet.html Creates a new DashSet with a capacity of 0. ```rust use dashmap::DashSet; let games = DashSet::new(); games.insert("Veloren"); ``` -------------------------------- ### product Source: https://docs.rs/dashmap/6.2.1/dashmap/rayon/map/struct.IterMut.html Multiplies all the items in the iterator. ```APIDOC ## product

(self) -> P ### Description Multiplies all the items in the iterator. ### Method product ### Type Constraints - `P: Send + Product + Product` ### Returns - `P` - The product of all items. ``` -------------------------------- ### product Source: https://docs.rs/dashmap/6.2.1/dashmap/rayon/map/struct.Iter.html Computes the product of all items in the iterator. ```APIDOC ## product ### Description Multiplies all the items in the iterator. ### Method product ### Signature `fn product

(self) -> P` ### Type Parameters - `P` (Send + Product + Product) - The type of the product. ### Returns - `P` - The product of all items. ``` -------------------------------- ### Ref::pair Source: https://docs.rs/dashmap/6.2.1/dashmap/mapref/one/struct.Ref.html Returns a tuple of references to the key and value of the entry. ```APIDOC ## Ref::pair ### Description Returns a tuple of references to the key and value of the entry. ### Method pair ### Signature pub fn pair(&self) -> (&K, &V) ### Parameters None ### Returns - **(&K, &V)** - A tuple containing references to the key and value. ``` -------------------------------- ### into_inner Source: https://docs.rs/dashmap/6.2.1/dashmap/struct.ReadOnlyView.html Consumes the `ReadOnlyView` and returns the underlying `DashMap`. ```APIDOC ## into_inner ### Description Consumes this `ReadOnlyView`, returning the underlying `DashMap`. ### Method into_inner ### Signature `pub fn into_inner(self) -> DashMap` ### Parameters - `self` - The `ReadOnlyView` to consume. ### Returns - `DashMap` - The underlying `DashMap`. ```