pub struct RegexMap<V> { /* private fields */ }
Expand description
Associative container where the keys are regular expressions, based on the regex::RegexSet
data structure.
Implementations§
Source§impl<V> RegexMap<V>
impl<V> RegexMap<V>
Sourcepub fn new<I, S>(items: I) -> Self
pub fn new<I, S>(items: I) -> Self
Create a new RegexMap
from iterator over (expression, value) pairs, where the expression is &str
-like.
use regex_map::RegexMap;
let map = RegexMap::new([
("foo", 1),
("bar", 2),
("foobar", 3),
("^foo$", 4),
("^bar$", 5),
("^foobar$", 6),
]);
assert_eq!(map.get("foo").cloned().collect::<Vec<_>>(), vec![1, 4]);
assert_eq!(map.get("bar").cloned().collect::<Vec<_>>(), vec![2, 5], );
assert_eq!(map.get("foobar").cloned().collect::<Vec<_>>(), vec![1, 2, 3, 6]);
assert_eq!(map.get("XXX foo XXX").cloned().collect::<Vec<_>>(), vec![1]);
assert_eq!(map.get("XXX bar XXX").cloned().collect::<Vec<_>>(), vec![2]);
Sourcepub fn get(&self, key: &str) -> impl Iterator<Item = &V>
pub fn get(&self, key: &str) -> impl Iterator<Item = &V>
Get an iterator over all values whose regular expression matches the given key.
To get first matching value, use can use .next()
on the returned iterator:
use regex_map::RegexMap;
let map = RegexMap::new([
("foo", 1),
("bar", 2),
]);
assert_eq!(map.get("foo").next(), Some(&1));
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Check if the given key matches any of the regular expressions.
Auto Trait Implementations§
impl<V> Freeze for RegexMap<V>
impl<V> RefUnwindSafe for RegexMap<V>where
V: RefUnwindSafe,
impl<V> Send for RegexMap<V>where
V: Send,
impl<V> Sync for RegexMap<V>where
V: Sync,
impl<V> Unpin for RegexMap<V>where
V: Unpin,
impl<V> UnwindSafe for RegexMap<V>where
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
Mutably borrows from an owned value. Read more