pub trait Pattern<'a> {
// Required method
fn find_in(&self, value: &'a str) -> Vec<Match<'a>>;
// Provided methods
fn find_prefix_in(&self, value: &'a str) -> Vec<Match<'a>> { ... }
fn find_suffix_in(&self, value: &'a str) -> Vec<Match<'a>> { ... }
fn find_one_in(&self, value: &'a str) -> Option<Match<'a>> { ... }
fn find_one_prefix_in(&self, value: &'a str) -> Option<Match<'a>> { ... }
fn find_one_suffix_in(&self, value: &'a str) -> Option<Match<'a>> { ... }
}Expand description
A string Pattern.
The type implementing it can be used as a pattern for &str,
by default it is implemented for the following types:
| Pattern type | Match condition |
|---|---|
char | is contained in string |
&str | is substring |
String | is substring |
&[char] | any char is contained in string |
&[&str] | any &str is substring |
F: Fn(&str) -> bool | F returns true for substring |
Regex | Regex match substring |
Required Methods§
Provided Methods§
Sourcefn find_prefix_in(&self, value: &'a str) -> Vec<Match<'a>>
fn find_prefix_in(&self, value: &'a str) -> Vec<Match<'a>>
Find all occurences of the pattern in the given &str that are prefixes.
§Examples
assert!("ab".find_prefix_in("cdab").is_empty());
assert_eq!("ab".find_prefix_in("abcd"), vec![Match::new("abcd", 0, 2)]);Sourcefn find_suffix_in(&self, value: &'a str) -> Vec<Match<'a>>
fn find_suffix_in(&self, value: &'a str) -> Vec<Match<'a>>
Find all occurences of the pattern in the given &str that are suffixes.
§Examples
assert!("ab".find_suffix_in("abcd").is_empty());
assert_eq!("ab".find_suffix_in("cdab"), vec![Match::new("cdab", 2, 4)]);Sourcefn find_one_in(&self, value: &'a str) -> Option<Match<'a>>
fn find_one_in(&self, value: &'a str) -> Option<Match<'a>>
Find one occurrence of the pattern in the given &str.
§Examples
assert!("ab".find_one_in("cd").is_none());
assert_eq!("ab".find_one_in("cdab"), Some(Match::new("cdab", 2, 4)));