Struct fm::FMBuilder

source ·
pub struct FMBuilder<'a> { /* private fields */ }
Expand description

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(ptn_re, text_re)
                        .build()
                        .unwrap();
assert!(matcher.matches("a a").is_ok());
assert!(matcher.matches("a b").is_err());

Implementations§

source§

impl<'a> FMBuilder<'a>

source

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

Create a new FMBuilder with default options.

source

pub fn output_formatter(self, output_formatter: OutputFormatter) -> Self

source

pub fn name_matcher(self, ptn_re: Regex, text_re: Regex) -> Self

Add a name matcher (ptn_re, text_re). 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(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.

Multiple name matchers are allowed: they are matched in the order they were added to FMBuilder.

source

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

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.

source

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

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

source

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

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

source

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

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

source

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

Turn this FMBuilder into a FMatcher.

Trait Implementations§

source§

impl<'a> Debug for FMBuilder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for FMBuilder<'a>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.