[−][src]Struct cfgmap::CfgMap
A configuration map, containing helper functions and effectively being a wrapper
around a HashMap
s.
Fields
default: String
A path to the default subobject.
Implementations
impl CfgMap
[src]
pub fn new() -> CfgMap
[src]
Creates a new empty CfgMap.
pub fn with_hashmap(map: HashMap<String, CfgValue>) -> CfgMap
[src]
Initialises a CfgMap
using the map
that's passed in.
pub fn from_json(value: JsonValue) -> CfgMap
[src]
Initialises a CfgMap
from a json Value
.
pub fn from_toml(value: TomlValue) -> CfgMap
[src]
Initialises a CfgMap
from a toml Value
.
pub fn from_yaml(value: YamlValue) -> CfgMap
[src]
Initialises a CfgMap
from a yaml Value
.
pub fn add(
&mut self,
key: &str,
value: CfgValue
) -> Result<Option<CfgValue>, ()>
[src]
&mut self,
key: &str,
value: CfgValue
) -> Result<Option<CfgValue>, ()>
Adds a new entry in the configuration.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
get the inner submap a/b/...y/
, and add z
onto it. This is for convenience sake,
as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
In order to add a default value to a normal submap - you would need to do this manually,
as this function will always use get_mut
.
Examples
use cfgmap::{CfgMap, CfgValue::*}; let mut cmap = CfgMap::new(); // Works - a root add like this will always work. assert!(cmap.add("k1", Int(5)).is_ok()); // Doesn't work, because k1 isn't a map. assert!(cmap.add("k1/k2", Int(10)).is_err()); // Works - returns the old value. let r = cmap.add("k1", Float(8.0)); assert_eq!(Ok(Some(Int(5))), r);
Return values
Err
if the path as specified bykey
isn't found. In the case above for example,get_mut("a")
returns aNone
.Ok(Some(CfgValue))
if the path as specified by key already contained a value, and was overwritten. In this case, the old value is returned.Ok(None)
otherwise.
pub fn get(&self, key: &str) -> Option<&CfgValue>
[src]
Gets a reference to a value from within the configuration.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Returns None
if the key doesn't exist.
Examples
use cfgmap::{CfgMap, CfgValue::*, Condition::*, Checkable}; let mut cmap = CfgMap::new(); let mut submap = CfgMap::new(); submap.add("key", Int(5)); cmap.add("sub", Map(submap)); assert!(cmap.get("sub").check_that(IsMap)); assert!(cmap.get("sub/key").check_that(IsExactlyInt(5)));
pub fn get_mut(&mut self, key: &str) -> Option<&mut CfgValue>
[src]
Gets a mutable reference to a value from within the configuration.
Returns None
if the key doesn't exist.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Condition::*, Checkable}; let mut cmap = CfgMap::new(); let mut submap = CfgMap::new(); cmap.add("sub", Map(submap)); let mut submap = cmap.get_mut("sub"); assert!(submap.check_that(IsMap)); submap.unwrap().as_map_mut().unwrap().add("key", Int(5)); assert!(cmap.get_mut("sub/key").check_that(IsExactlyInt(5)));
pub fn remove(&mut self, key: &str) -> Option<CfgValue>
[src]
Deletes a key from the map, and returns the value associated with it.
Returns None
if the key doesn't exist.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Condition::*, Checkable}; let mut cmap = CfgMap::new(); cmap.add("sub", Map(CfgMap::new())); cmap.add("sub/int", Int(5)); let num = cmap.remove("sub/int"); let nothing = cmap.remove("sub/nothing"); assert!(cmap.get("sub/int").is_none()); assert!(num.check_that(IsExactlyInt(5))); assert!(nothing.is_none());
pub fn remove_if(&mut self, key: &str, condition: Condition) -> Option<CfgValue>
[src]
Deletes a key from the map, and returns the value associated with it, if the value obeys the conditions as passed. Useful for when you want to make sure to avoid deleting another value.
Returns None
if the key doesn't exist, or the value associated with the key doesn't obey the condition.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Condition::*, Checkable}; let mut cmap = CfgMap::new(); cmap.add("sub", Map(CfgMap::new())); cmap.add("sub/int", Int(5)); let float = cmap.remove_if("sub/int", IsFloat); assert!(cmap.get("sub/int").is_some()); assert!(float.is_none()); let int = cmap.remove_if("sub/int", IsInt); assert!(cmap.get("sub/int").is_none()); assert!(int.check_that(IsExactlyInt(5)));
pub fn remove_entry(&mut self, key: &str) -> Option<(String, CfgValue)>
[src]
Deletes a key from the map, and returns the key and value associated with it.
Returns None
if the key doesn't exist.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Condition::*, Checkable}; let mut cmap = CfgMap::new(); cmap.add("sub", Map(CfgMap::new())); cmap.add("sub/int", Int(5)); let (key, num) = cmap.remove_entry("sub/int").unwrap(); let nothing = cmap.remove("sub/nothing"); assert!(cmap.get("sub/int").is_none()); assert_eq!(key, "int"); assert!(num.check_that(IsExactlyInt(5))); assert!(nothing.is_none());
pub fn remove_entry_if(
&mut self,
key: &str,
condition: Condition
) -> Option<(String, CfgValue)>
[src]
&mut self,
key: &str,
condition: Condition
) -> Option<(String, CfgValue)>
Deletes a key from the map, and returns the key and value associated with it, if the value obeys the conditions as passed. Useful for when you want to make sure to avoid deleting another value.
Returns None
if the key doesn't exist, or the value associated with the key doesn't obey the condition.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Condition::*, Checkable}; let mut cmap = CfgMap::new(); cmap.add("sub", Map(CfgMap::new())); cmap.add("sub/int", Int(5)); let float = cmap.remove_entry_if("sub/int", IsFloat); assert!(cmap.get("sub/int").is_some()); assert!(float.is_none()); let (key, int) = cmap.remove_entry_if("sub/int", IsInt).unwrap(); assert!(cmap.get("sub/int").is_none()); assert_eq!(key, "int"); assert!(int.check_that(IsExactlyInt(5)));
pub fn contains_key(&self, key: &str) -> bool
[src]
Checks whether a certain path exists.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Condition::*, Checkable}; let mut cmap = CfgMap::new(); let mut submap = CfgMap::new(); cmap.add("num", Int(10)); submap.add("num", Int(20)); cmap.add("sub", Map(submap)); assert!(cmap.contains_key("num")); assert!(cmap.contains_key("sub/num"));
pub fn get_option(&self, category: &str, option: &str) -> Option<&CfgValue>
[src]
Gets a reference to an option within the configuration.
It first tries to get
category/option
within the normal values. If this doesn't exist, it will then
try to retrieve option
from the default path instead (self.default/option
).
Note that if default
wasn't set on construction, this function will instead retrieve
the value from the root directory (option
) directly.
Returns None
if the key doesn't exist in either map.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Checkable, Condition::*}; let mut cmap = CfgMap::new(); let mut submap = CfgMap::new(); submap.add("OP1", Int(5)); cmap.add("OP1", Int(8)); cmap.add("sub", Map(submap)); assert!(cmap.get_option("sub", "OP1").check_that(IsExactlyInt(5))); assert!(cmap.get_option("sub", "OP1").check_that(IsExactlyInt(5))); assert!(cmap.get_option("sub", "OP2").is_none());
pub fn update_option(
&mut self,
category: &str,
option: &str,
to: CfgValue
) -> Option<CfgValue>
[src]
&mut self,
category: &str,
option: &str,
to: CfgValue
) -> Option<CfgValue>
Updates the option with the new value to
.
It first tries to get
category/option
within the normal values. If this doesn't exist, it will then
try to retrieve option
from the default path instead (self.default/option
).
Note that if default
wasn't set on construction, this function will instead retrieve
the value from the root directory (option
) directly.
The key
can be of the form of the path "a/b/...y/z/"
, in which case it will
go through the inner submaps "a/b/..."
until a submap isn't found, or the end is reached.
This is for convenience sake, as doing this manually can prove to be verbose.
This key can also index into lists. So, for example a/0/b
would try checking if "a"
is a list, and index into it. Otherwise it will try to find an internal map with the key 0
.
Examples
use cfgmap::{CfgMap, CfgValue::*, Checkable, Condition::*}; let mut cmap = CfgMap::new(); let mut submap = CfgMap::new(); submap.add("OP1", Int(5)); cmap.add("OP1", Int(8)); cmap.add("sub", Map(submap)); let ol1 = cmap.update_option("sub", "OP1", Int(10)); let ol2 = cmap.update_option("foo", "OP1", Int(16)); let ol3 = cmap.update_option("sub", "OP2", Int(99)); assert!(cmap.get_option("sub", "OP1").check_that(IsExactlyInt(10))); assert!(cmap.get_option("foo", "OP1").check_that(IsExactlyInt(16))); assert!(cmap.get_option("sub", "OP2").is_none()); assert_eq!(ol1, Some(Int(5))); assert_eq!(ol2, Some(Int(8))); assert_eq!(ol3, None);
Methods from Deref<Target = HashMap<String, CfgValue>>
pub fn capacity(&self) -> usize
1.0.0[src]
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the HashMap<K, V>
might be able to hold
more, but is guaranteed to be able to hold at least this many.
Examples
use std::collections::HashMap; let map: HashMap<i32, i32> = HashMap::with_capacity(100); assert!(map.capacity() >= 100);
pub fn keys(&self) -> Keys<K, V>
1.0.0[src]
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for key in map.keys() { println!("{}", key); }
pub fn values(&self) -> Values<K, V>
1.0.0[src]
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for val in map.values() { println!("{}", val); }
pub fn values_mut(&mut self) -> ValuesMut<K, V>
1.10.0[src]
An iterator visiting all values mutably in arbitrary order.
The iterator element type is &'a mut V
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for val in map.values_mut() { *val = *val + 10; } for val in map.values() { println!("{}", val); }
pub fn iter(&self) -> Iter<K, V>
1.0.0[src]
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V)
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for (key, val) in map.iter() { println!("key: {} val: {}", key, val); }
pub fn iter_mut(&mut self) -> IterMut<K, V>
1.0.0[src]
An iterator visiting all key-value pairs in arbitrary order,
with mutable references to the values.
The iterator element type is (&'a K, &'a mut V)
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); // Update all values for (_, val) in map.iter_mut() { *val *= 2; } for (key, val) in &map { println!("key: {} val: {}", key, val); }
pub fn len(&self) -> usize
1.0.0[src]
Returns the number of elements in the map.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); assert_eq!(a.len(), 0); a.insert(1, "a"); assert_eq!(a.len(), 1);
pub fn is_empty(&self) -> bool
1.0.0[src]
Returns true
if the map contains no elements.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); assert!(a.is_empty()); a.insert(1, "a"); assert!(!a.is_empty());
pub fn drain(&mut self) -> Drain<K, V>
1.6.0[src]
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); a.insert(1, "a"); a.insert(2, "b"); for (k, v) in a.drain().take(1) { assert!(k == 1 || k == 2); assert!(v == "a" || v == "b"); } assert!(a.is_empty());
pub fn clear(&mut self)
1.0.0[src]
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); a.insert(1, "a"); a.clear(); assert!(a.is_empty());
pub fn hasher(&self) -> &S
1.9.0[src]
Returns a reference to the map's BuildHasher
.
Examples
use std::collections::HashMap; use std::collections::hash_map::RandomState; let hasher = RandomState::new(); let map: HashMap<i32, i32> = HashMap::with_hasher(hasher); let hasher: &RandomState = map.hasher();
pub fn reserve(&mut self, additional: usize)
1.0.0[src]
Reserves capacity for at least additional
more elements to be inserted
in the HashMap
. The collection may reserve more space to avoid
frequent reallocations.
Panics
Panics if the new allocation size overflows usize
.
Examples
use std::collections::HashMap; let mut map: HashMap<&str, i32> = HashMap::new(); map.reserve(10);
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
[src]
🔬 This is a nightly-only experimental API. (try_reserve
)
new API
Tries to reserve capacity for at least additional
more elements to be inserted
in the given HashMap<K,V>
. The collection may reserve more space to avoid
frequent reallocations.
Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Examples
#![feature(try_reserve)] use std::collections::HashMap; let mut map: HashMap<&str, isize> = HashMap::new(); map.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
pub fn shrink_to_fit(&mut self)
1.0.0[src]
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
Examples
use std::collections::HashMap; let mut map: HashMap<i32, i32> = HashMap::with_capacity(100); map.insert(1, 2); map.insert(3, 4); assert!(map.capacity() >= 100); map.shrink_to_fit(); assert!(map.capacity() >= 2);
pub fn shrink_to(&mut self, min_capacity: usize)
[src]
🔬 This is a nightly-only experimental API. (shrink_to
)
new API
Shrinks the capacity of the map with a lower limit. It will drop down no lower than the supplied limit while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
Panics if the current capacity is smaller than the supplied minimum capacity.
Examples
#![feature(shrink_to)] use std::collections::HashMap; let mut map: HashMap<i32, i32> = HashMap::with_capacity(100); map.insert(1, 2); map.insert(3, 4); assert!(map.capacity() >= 100); map.shrink_to(10); assert!(map.capacity() >= 10); map.shrink_to(0); assert!(map.capacity() >= 2);
pub fn entry(&mut self, key: K) -> Entry<K, V>
1.0.0[src]
Gets the given key's corresponding entry in the map for in-place manipulation.
Examples
use std::collections::HashMap; let mut letters = HashMap::new(); for ch in "a short treatise on fungi".chars() { let counter = letters.entry(ch).or_insert(0); *counter += 1; } assert_eq!(letters[&'s'], 2); assert_eq!(letters[&'t'], 3); assert_eq!(letters[&'u'], 1); assert_eq!(letters.get(&'y'), None);
pub fn get<Q>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), None);
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.40.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.get_key_value(&1), Some((&1, &"a"))); assert_eq!(map.get_key_value(&2), None);
pub fn contains_key<Q>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns true
if the map contains a value for the specified key.
The key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.contains_key(&1), true); assert_eq!(map.contains_key(&2), false);
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); if let Some(x) = map.get_mut(&1) { *x = "b"; } assert_eq!(map[&1], "b");
pub fn insert(&mut self, k: K, v: V) -> Option<V>
1.0.0[src]
Inserts a key-value pair into the map.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old
value is returned. The key is not updated, though; this matters for
types that can be ==
without being identical. See the module-level
documentation for more.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); assert_eq!(map.insert(37, "a"), None); assert_eq!(map.is_empty(), false); map.insert(37, "b"); assert_eq!(map.insert(37, "c"), Some("b")); assert_eq!(map[&37], "c");
pub fn remove<Q>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.remove(&1), Some("a")); assert_eq!(map.remove(&1), None);
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.27.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.remove_entry(&1), Some((1, "a"))); assert_eq!(map.remove(&1), None);
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&K, &mut V) -> bool,
1.18.0[src]
F: FnMut(&K, &mut V) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v)
such that f(&k,&mut v)
returns false
.
Examples
use std::collections::HashMap; let mut map: HashMap<i32, i32> = (0..8).map(|x|(x, x*10)).collect(); map.retain(|&k, _| k % 2 == 0); assert_eq!(map.len(), 4);
pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<K, V, S>
[src]
hash_raw_entry
)Creates a raw entry builder for the HashMap.
Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched. After this, insertions into a vacant entry still require an owned key to be provided.
Raw entries are useful for such exotic situations as:
- Hash memoization
- Deferring the creation of an owned key until it is known to be required
- Using a search key that doesn't work with the Borrow trait
- Using custom comparison logic without newtype wrappers
Because raw entries provide much more low-level control, it's much easier
to put the HashMap into an inconsistent state which, while memory-safe,
will cause the map to produce seemingly random results. Higher-level and
more foolproof APIs like entry
should be preferred when possible.
In particular, the hash used to initialized the raw entry must still be consistent with the hash of the key that is ultimately stored in the entry. This is because implementations of HashMap may need to recompute hashes when resizing, at which point only the keys are available.
Raw entries give mutable access to the keys. This must not be used to modify how the key would compare or hash, as the map will not re-evaluate where the key should go, meaning the keys may become "lost" if their location does not reflect their state. For instance, if you change a key so that the map now contains keys which compare equal, search may start acting erratically, with two keys randomly masking each other. Implementations are free to assume this doesn't happen (within the limits of memory-safety).
pub fn raw_entry(&self) -> RawEntryBuilder<K, V, S>
[src]
hash_raw_entry
)Creates a raw immutable entry builder for the HashMap.
Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched.
This is useful for
- Hash memoization
- Using a search key that doesn't work with the Borrow trait
- Using custom comparison logic without newtype wrappers
Unless you are in such a situation, higher-level and more foolproof APIs like
get
should be preferred.
Immutable raw entries have very limited use; you might instead want raw_entry_mut
.
Trait Implementations
impl Clone for CfgMap
[src]
impl Debug for CfgMap
[src]
impl Deref for CfgMap
[src]
type Target = HashMap<String, CfgValue>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl DerefMut for CfgMap
[src]
impl From<CfgMap> for CfgValue
[src]
impl From<Value> for CfgMap
[src]
impl From<Value> for CfgMap
[src]
impl PartialEq<CfgMap> for CfgMap
[src]
impl StructuralPartialEq for CfgMap
[src]
Auto Trait Implementations
impl RefUnwindSafe for CfgMap
impl Send for CfgMap
impl Sync for CfgMap
impl Unpin for CfgMap
impl UnwindSafe for CfgMap
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,