pub struct SeqMap<K, V>{ /* private fields */ }Expand description
Implementations§
source§impl<K, V> SeqMap<K, V>
impl<K, V> SeqMap<K, V>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty SeqMap.
§Examples
use seq_map::SeqMap;
let map: SeqMap<String, i32> = SeqMap::new();sourcepub fn insert(&mut self, key: K, value: V) -> Result<(), SeqMapError>
pub fn insert(&mut self, key: K, value: V) -> Result<(), SeqMapError>
Inserts a key-value pair into the map.
Returns an error if the key already exists.
§Errors
Returns SeqMapError::KeyAlreadyExists if the key is already present.
§Examples
use seq_map::SeqMap;
let mut map = SeqMap::new();
map.insert("key".to_string(), 42).unwrap();
assert!(map.insert("key".to_string(), 43).is_err());sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
Returns None if the key does not exist.
§Examples
use seq_map::SeqMap;
let mut map = SeqMap::new();
map.insert("key".to_string(), 42).unwrap();
if let Some(value) = map.get_mut(&"key".to_string()) {
*value = 100;
}
assert_eq!(map[&"key".to_string()], 100);sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of key-value pairs in the map.
§Examples
use seq_map::SeqMap;
let mut map = SeqMap::new();
assert_eq!(map.len(), 0);
map.insert("key", 42).unwrap();
assert_eq!(map.len(), 1);sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
§Examples
use seq_map::SeqMap;
let map: SeqMap<String, i32> = SeqMap::new();
assert!(map.is_empty());sourcepub fn keys(&self) -> impl Iterator<Item = &K>
pub fn keys(&self) -> impl Iterator<Item = &K>
Returns an iterator over the keys of the map in insertion order.
§Examples
use seq_map::SeqMap;
let mut map = SeqMap::new();
map.insert("a".to_string(), 1).unwrap();
map.insert("b".to_string(), 2).unwrap();
let keys: Vec<_> = map.keys().cloned().collect();
assert_eq!(keys, vec!["a", "b"]);sourcepub fn values(&self) -> impl Iterator<Item = &V>
pub fn values(&self) -> impl Iterator<Item = &V>
Returns an iterator over the values of the map in insertion order.
§Examples
use seq_map::SeqMap;
let mut map = SeqMap::new();
map.insert("a".to_string(), 1).unwrap();
map.insert("b".to_string(), 2).unwrap();
let values: Vec<_> = map.values().cloned().collect();
assert_eq!(values, vec![1, 2]);sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Retrieves a reference to the value corresponding to the key.
This method performs a faster lookup using the internal HashMap.
For a slower but simpler lookup, see slow_get.
§Examples
use seq_map::SeqMap;
let mut map = SeqMap::new();
map.insert("key".to_string(), 42).unwrap();
assert_eq!(map.get(&"key".to_string()), Some(&42));Trait Implementations§
source§impl<K, V> From<&[(K, V)]> for SeqMap<K, V>
impl<K, V> From<&[(K, V)]> for SeqMap<K, V>
source§fn from(slice: &[(K, V)]) -> Self
fn from(slice: &[(K, V)]) -> Self
Creates a SeqMap from a slice of key-value pairs.
If duplicate keys are present in the slice, the first occurrence is kept, and subsequent duplicates are ignored.
§Examples
use seq_map::SeqMap;
let pairs = vec![
("a".to_string(), 1),
("b".to_string(), 2),
];
let map: SeqMap<_, _> = SeqMap::from(&pairs[..]);
assert_eq!(map.len(), 2);source§impl<'a, K, V> IntoIterator for &'a SeqMap<K, V>
impl<'a, K, V> IntoIterator for &'a SeqMap<K, V>
source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Returns an iterator over references to the key-value pairs in insertion order.
This implementation allows you to iterate over references to the keys and values
without consuming the SeqMap. It’s useful for scenarios where you want to inspect
the contents of the map without modifying it.
§Examples
§Iterating Over References
use seq_map::SeqMap;
let mut map = SeqMap::new();
map.insert("a".to_string(), 1).unwrap();
map.insert("b".to_string(), 2).unwrap();
map.insert("c".to_string(), 3).unwrap();
for (key, value) in &map {
println!("{}: {}", key, value);
}§Collecting into a Vector of References
use seq_map::SeqMap;
let mut map = SeqMap::new();
map.insert("x".to_string(), 100).unwrap();
map.insert("y".to_string(), 200).unwrap();
let entries: Vec<_> = (&map).into_iter().collect();
assert_eq!(
entries,
vec![
(&"x".to_string(), &100),
(&"y".to_string(), &200),
]
);impl<K, V: Eq> Eq for SeqMap<K, V>
impl<K, V> StructuralPartialEq for SeqMap<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for SeqMap<K, V>
impl<K, V> RefUnwindSafe for SeqMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SeqMap<K, V>
impl<K, V> Sync for SeqMap<K, V>
impl<K, V> Unpin for SeqMap<K, V>
impl<K, V> UnwindSafe for SeqMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)