[][src]Struct fm::FMBuilder

pub struct FMBuilder<'a> { /* fields omitted */ }

Build up a FMatcher allowing the setting of options.

use {fm::FMBuilder, regex::Regex};

let ptn_re = Regex::new(r"\$.+?\b").unwrap();
let text_re = Regex::new(r".+?\b").unwrap();
let matcher = FMBuilder::new("$1 $1")
                        .unwrap()
                        .name_matcher(Some((ptn_re, text_re)))
                        .build()
                        .unwrap();
assert!(matcher.matches("a a").is_ok());
assert!(matcher.matches("a b").is_err());

Implementations

impl<'a> FMBuilder<'a>[src]

pub fn new(ptn: &'a str) -> Result<Self, Box<dyn Error>>[src]

Create a new FMBuilder with default options.

pub fn name_matcher(self, matcher: Option<(Regex, Regex)>) -> Self[src]

Add a name matcher Some((ptn_re, text_re)) (or unset it with None). Defaults to None.

Name matchers allow you to ensure that different parts of the text match without specifying precisely what they match. For example, if you have output where you want to ensure that two locations always match the same name, but the name is non-deterministic you can allow the use of $ wildcards in your pattern:

use {fm::FMBuilder, regex::Regex};

let ptn_re = Regex::new(r"\$.+?\b").unwrap();
let text_re = Regex::new(r".+?\b").unwrap();
let matcher = FMBuilder::new("$1 b $1")
                        .unwrap()
                        .name_matcher(Some((ptn_re, text_re)))
                        .build()
                        .unwrap();
assert!(matcher.matches("a b a").is_ok());
assert!(matcher.matches("a b b").is_err());

Note that if a line in the pattern uses name matching, it can only use the wildcard operator at the end of the line (so, for the above name matcher, $1... is allowed but ...$1 or ...$1... is not allowed). Invalid combinations of wildcards and name matching are caught when a pattern is built.

pub fn distinct_name_matching(self, yes: bool) -> Self[src]

If yes, then different names cannot match the same text value. For example if $1 binds to a then $2 will refuse to match against a (though $1 will continue to match against only a). Defaults to false.

pub fn ignore_leading_whitespace(self, yes: bool) -> Self[src]

If yes, then each line's leading whitespace will be ignored in both pattern and text; otherwise leading whitespace must match. Defaults to true.

pub fn ignore_trailing_whitespace(self, yes: bool) -> Self[src]

If yes, then each line's trailing whitespace will be ignored in both pattern and text; otherwise trailing whitespace must match. Defaults to true.

pub fn ignore_surrounding_blank_lines(self, yes: bool) -> Self[src]

If yes, blank lines at the start and end of both the pattern and text are ignored for matching purposes.

pub fn build(self) -> Result<FMatcher<'a>, Box<dyn Error>>[src]

Turn this FMBuilder into a FMatcher.

Trait Implementations

impl<'a> Debug for FMBuilder<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for FMBuilder<'a>

impl<'a> Send for FMBuilder<'a>

impl<'a> Sync for FMBuilder<'a>

impl<'a> Unpin for FMBuilder<'a>

impl<'a> UnwindSafe for FMBuilder<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.