pub struct RegexMap<V> { /* private fields */ }
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::bytes::RegexMap;
let map = RegexMap::new([
("foo", 1),
("bar", 2),
("foobar", 3),
("^foo$", 4),
("^bar$", 5),
("^foobar$", 6),
]);
assert_eq!(map.get(b"foo").cloned().collect::<Vec<_>>(), vec![1, 4]);
assert_eq!(map.get(b"bar").cloned().collect::<Vec<_>>(), vec![2, 5], );
assert_eq!(map.get(b"foobar").cloned().collect::<Vec<_>>(), vec![1, 2, 3, 6]);
assert_eq!(map.get(b"XXX foo XXX").cloned().collect::<Vec<_>>(), vec![1]);
assert_eq!(map.get(b"XXX bar XXX").cloned().collect::<Vec<_>>(), vec![2]);
Sourcepub fn get(&self, key: &[u8]) -> impl Iterator<Item = &V>
pub fn get(&self, key: &[u8]) -> 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::bytes::RegexMap;
let map = RegexMap::new([
("foo", 1),
("bar", 2),
]);
assert_eq!(map.get(b"foo").next(), Some(&1));
Sourcepub fn contains_key(&self, key: &[u8]) -> bool
pub fn contains_key(&self, key: &[u8]) -> 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