Struct RegexMap

Source
pub struct RegexMap<V> { /* private fields */ }

Implementations§

Source§

impl<V> RegexMap<V>

Source

pub fn new<I, S>(items: I) -> Self
where I: IntoIterator<Item = (S, V)>, S: AsRef<str>,

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]);
Source

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));
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.