Pattern

Trait Pattern 

Source
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 typeMatch condition
charis contained in string
&stris substring
Stringis substring
&[char]any char is contained in string
&[&str]any &str is substring
F: Fn(&str) -> boolF returns true for substring
RegexRegex match substring

Required Methods§

Source

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Find all occurences of the pattern in the given &str.

§Examples
assert!("ab".find_in("cd").is_empty());
assert_eq!("ab".find_in("cabd"), vec![Match::new("cabd", 1, 3)]);

Provided Methods§

Source

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

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

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

fn find_one_prefix_in(&self, value: &'a str) -> Option<Match<'a>>

Find one occurrence of the pattern in the given &str that is prefix.

§Examples
assert!("ab".find_one_prefix_in("cdab").is_none());
assert_eq!("ab".find_one_prefix_in("abcd"), Some(Match::new("abcd", 0, 2)));
Source

fn find_one_suffix_in(&self, value: &'a str) -> Option<Match<'a>>

Find one occurrence of the pattern in the given &str that is suffix.

§Examples
assert!("ab".find_one_suffix_in("abcd").is_none());
assert_eq!("ab".find_one_suffix_in("cdab"), Some(Match::new("cdab", 2, 4)));

Implementations on Foreign Types§

Source§

impl<'a> Pattern<'a> for &str

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a> Pattern<'a> for char

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a> Pattern<'a> for String

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a> Pattern<'a> for Regex

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a> Pattern<'a> for [&str]

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a> Pattern<'a> for [char]

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a, const N: usize> Pattern<'a> for &[&str; N]

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a, const N: usize> Pattern<'a> for &[char; N]

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a, const N: usize> Pattern<'a> for [&str; N]

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Source§

impl<'a, const N: usize> Pattern<'a> for [char; N]

Source§

fn find_in(&self, value: &'a str) -> Vec<Match<'a>>

Implementors§

Source§

impl<'a: 'b, 'b, F> Pattern<'a> for F
where F: Fn(&'b str) -> bool,