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() -> SeqMap<K, V>
pub fn new() -> SeqMap<K, V>
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 contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Checks if the map contains a key.
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]);
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
pub fn get_index(&self, key: &K) -> Option<usize>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
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> Extend<(K, V)> for SeqMap<K, V>
impl<K, V> Extend<(K, V)> for SeqMap<K, V>
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)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)]) -> SeqMap<K, V>
fn from(slice: &[(K, V)]) -> SeqMap<K, V>
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<K, V> FromIterator<(K, V)> for SeqMap<K, V>
Creates a SeqMap
from an iterator of key-value pairs.
impl<K, V> FromIterator<(K, V)> for SeqMap<K, V>
Creates a SeqMap
from an iterator of key-value pairs.
If duplicate keys are present in the iterator, the first occurrence is kept, and subsequent duplicates are silently ignored.
Source§impl<K, V> Index<&K> for SeqMap<K, V>
impl<K, V> Index<&K> for SeqMap<K, V>
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) -> <&'a SeqMap<K, V> as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a SeqMap<K, V> as IntoIterator>::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),
]
);
Source§impl<'a, K, V> IntoIterator for &'a mut SeqMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut SeqMap<K, V>
Source§impl<K, V> IntoIterator for SeqMap<K, V>
impl<K, V> IntoIterator for SeqMap<K, V>
impl<K, V> Eq 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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);