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 rust &str.

By default it is implemented for the following types: | Pattern type | Match condition | |––––––––––––––––|—————————————–| | rust char | is contained in string | | rust `&str | is substring | | rust String | is substring | | rust `&[char] | any char is contained in string | | rust `&[&str] | any &str is substring | | rust F: Fn(&str) -> bool | F returns rust true for substring | | rust Regex | rust Regex match substring |

Required Methods§

source

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

Find all occurences of the pattern in the given value.

Examples
use lexer::pattern::{Match, Pattern};

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 value that are prefixes.

Examples
use lexer::pattern::{Match, Pattern};

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 value that are suffixes.

Examples
use lexer::pattern::{Match, Pattern};

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 value.

Examples
use lexer::pattern::{Match, Pattern};

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 value that is prefix.

Examples
use lexer::pattern::{Match, Pattern};

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 value that is suffix.

Examples
use lexer::pattern::{Match, Pattern};

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,