pub struct CIndexMap<K, V> { /* private fields */ }Implementations§
Source§impl<K, V> CIndexMap<K, V>
impl<K, V> CIndexMap<K, V>
Sourcepub fn insert(&mut self, key: K, value: V) -> Result<()>
pub fn insert(&mut self, key: K, value: V) -> Result<()>
Inserts a new key/value pair into the map.
This function returns Ok(()) if the key/value pair was inserted successfully.
Sourcepub fn remove(&mut self, index: usize) -> Result<()>
pub fn remove(&mut self, index: usize) -> Result<()>
Removes an element at the specified index.
Sourcepub fn index(&self, index: usize) -> Result<&K>
pub fn index(&self, index: usize) -> Result<&K>
Returns the key to the entry at the specified index.
Use CIndexMap::get to get the value of the entry based off of the key.
Sourcepub fn get_no_peq(&self, key: K) -> Option<&V>
pub fn get_no_peq(&self, key: K) -> Option<&V>
Gets the value associated with the specified key.
This function is preferred for when the underlying Key/Value types for this map cannot,
for some reason, implement PartialEq.
This performs a raw memory comparison between the supplied value and the keys in the
current map. This comparison doesn’t work on a lot of dynamically sized types, like String
and Vec.
§Correct usage
use x_map::maps::CIndexMap;
let mut map = CIndexMap::new();
map.insert("foo", "bar").unwrap();
// Prints `map.get("foo").unwrap() = "bar"`
dbg!(map.get("foo").unwrap());
// Prints `map.get_no_peq("foo").unwrap() = "bar"`
dbg!(map.get_no_peq("foo").unwrap());§Incorrect usage
use x_map::maps::CIndexMap;
let string_one = String::from("foo");
let string_two = String::from("bar");
let mut map = CIndexMap::new();
map.insert(string_one.to_string(), string_two.to_string()).unwrap();
// Prints `map.get(string_one.to_string()) = Some("bar")`
dbg!(map.get(string_one.to_string()));
// Prints `map.get_no_peq(string_one.to_string()) = None`
dbg!(map.get_no_peq(string_one.to_string()));Source§impl<K: PartialEq, V> CIndexMap<K, V>
impl<K: PartialEq, V> CIndexMap<K, V>
Sourcepub fn get(&self, key: K) -> Option<&V>
pub fn get(&self, key: K) -> Option<&V>
Gets the value associated with the specified key.
Multiple implementations exist for get:
-
When
Kdoes not implementPartialEq,getwill perform bytewise comparison between the input and the map keys. This is a fallback implementation, and will not always produce expected results. This implementation will have unexpected results on dynamically sized types, such asStringandVec. -
When
KimplementsPartialEq,getwill callPartialEq::partial_eq()for comparison between the input and the map keys. This is the preferred implementation, and will produce the expected results.
Sourcepub fn contains_key(&self, key: K) -> bool
pub fn contains_key(&self, key: K) -> bool
Checks if the map contains the provided key.
- If it does, this function returns
true, - If it does not, this function returns
false.