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
Required Methods§
Sourcefn try_search<R: RegexPattern>(
&'h self,
pat: R,
) -> Result<Matches<'h, R>, Box<Error>>
fn try_search<R: RegexPattern>( &'h self, pat: R, ) -> Result<Matches<'h, R>, Box<Error>>
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§
Sourcefn search<R: RegexPattern>(&'h self, pat: R) -> Matches<'h, R> ⓘ
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
Sourcefn contains_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>
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.
Sourcefn matches_pat(&'h self, pat: impl RegexPattern) -> Result<bool, Box<Error>>
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.