Filter

Struct Filter 

Source
pub struct Filter { /* private fields */ }
Expand description

Filter demonstrates the use of FilteredRE2 by using Set as the backing search engine for the atoms produced by compile().

 use re2::{filtered::*, options::*, set::*};

 let mut builder = FilteredRE2Builder::with_min_atom_length(1);
 let x = builder.add("asdf", Options::default())?;
 let y = builder.add("asay", Options::default())?;
 let z = builder.add("as+", Options::default())?;
 let filter = Filter::compile(builder)?;

 let mut atoms = MatchedSetInfo::empty();
 let mut matches = MatchedSetInfo::empty();
 assert!(filter.all_matches("asdf asay asinine", &mut atoms, &mut matches));
 assert_eq!(matches.as_expression_slice(), &[x, y, z]);

 let matched_atoms: Vec<&str> = filter.get_atoms(&atoms)
   .map(|s| unsafe { s.as_str() })
   .collect();
 assert_eq!(&matched_atoms, &["a", "s", "asdf", "asay"]);
 let matched_regexps: Vec<&str> = filter.get_matches(&matches)
   .map(|r| r.as_re2().pattern())
   .collect();
 assert_eq!(&matched_regexps, &["asdf", "asay", "as+"]);

 assert!(filter.potential_matches("asdf asay asinine", &mut atoms, &mut matches));
 assert_eq!(matches.as_expression_slice(), &[x, y, z]);

Implementations§

Source§

impl Filter

Source

pub fn compile(builder: FilteredRE2Builder) -> Result<Self, SetError>

Extract the AtomSet from compiling the builder, then use it to construct a Set to search the atoms as literal case-insensitive strings.

Source

pub fn all_matches( &self, text: &str, atoms: &mut MatchedSetInfo, matches: &mut MatchedSetInfo, ) -> bool

Get all patterns matching text contributing to atoms in matches.

Source

pub fn potential_matches( &self, text: &str, atoms: &mut MatchedSetInfo, matches: &mut MatchedSetInfo, ) -> bool

Get all patterns contributing to the atoms which were found in text into matches.

Source

pub fn get_atoms<'a>( &'a self, atoms: &'a MatchedSetInfo, ) -> impl ExactSizeIterator<Item = StringView<'a>>

Look up the atom strings referenced in atoms.

Source

pub fn get_matches<'a>( &'a self, matches: &'a MatchedSetInfo, ) -> impl ExactSizeIterator<Item = InnerRE2<'a>>

Look up the pattern objects referenced in matches.

Auto Trait Implementations§

§

impl Freeze for Filter

§

impl RefUnwindSafe for Filter

§

impl Send for Filter

§

impl Sync for Filter

§

impl Unpin for Filter

§

impl UnwindSafe for Filter

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.