RegexHaystack

Trait RegexHaystack 

Source
pub trait RegexHaystack<'h> {
    // Required method
    fn try_search<R: RegexPattern>(
        &'h self,
        pat: R,
    ) -> Result<Matches<'h, R>, Box<Error>>;

    // Provided methods
    fn search<R: RegexPattern>(&'h self, pat: R) -> Matches<'h, R>  { ... }
    fn contains_pat(
        &'h self,
        pat: impl RegexPattern,
    ) -> Result<bool, Box<Error>> { ... }
    fn matches_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>> { ... }
}
Expand description

A type searcheable by DFAs

This type is used to create the Matches Iterator, a useful and configurable iterator over the matches in the Haystack, primarily on the Bytes type.

Required Methods§

An Iterator over the matches for a given RegexPattern

This Iterator will search through the entire range of the haystack. If the haystack is Strs, for example, then it will search through the Strs::byte_range. You can also set a custom range for search through the Matches::range method, which will reset the search to encompass the part of a TextRange that is clipped by the haystack.

This Iterator also implements DoubleEndedIterator, which means that you can get the elements in reverse order.

This function will return Err if the regex pattern is not valid. If you want a panicking variety, check out RegexHaystack::search

Provided Methods§

Source

fn search<R: RegexPattern>(&'h self, pat: R) -> Matches<'h, R>

An Iterator over the matches for a given RegexPattern

This Iterator will search through the entire range of the haystack. If the haystack is Strs, for example, then it will search through the Strs::byte_range. You can also set a custom range for search through the Matches::range method, which will reset the search to encompass the part of a TextRange that is clipped by the haystack.

This Iterator also implements DoubleEndedIterator, which means that you can get the elements in reverse order.

§Panics

This function will panic if the RegexPattern isn’t valid. If you want a non panicking variety, check out RegexHaystack::try_search

Source

fn contains_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>

Wether this haystack contains a match for a RegexPattern

This is equivalent to calling self.search().map(|iter| iter.next().is_some()).

This function will return Err if the regex pattern is not valid.

Source

fn matches_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>

Wether this haystack matches the RegexPattern exactly

This function will return Err if the regex pattern is not valid.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'b> RegexHaystack<'b> for Bytes

Source§

impl<'b> RegexHaystack<'b> for Strs<'b>

Source§

impl<'b> RegexHaystack<'b> for Text

Source§

impl<'s, S: Deref<Target = str>> RegexHaystack<'s> for S