[][src]Trait markedit::Matcher

pub trait Matcher {
    fn matches_event(&mut self, event: &Event) -> bool;

    fn first_match<'src, I, E>(self, events: I) -> Option<usize>
    where
        Self: Sized,
        I: IntoIterator<Item = E> + 'src,
        E: Borrow<Event<'src>> + 'src
, { ... }
fn is_in<'src, I, E>(self, events: I) -> bool
    where
        I: IntoIterator<Item = E> + 'src,
        E: Borrow<Event<'src>>,
        Self: Sized
, { ... }
fn then_start_of_next_line(self) -> StartOfNextLine<Self>
    where
        Self: Sized
, { ... }
fn fuse(self) -> OneShot<Self>
    where
        Self: Sized
, { ... }
fn falling_edge(self) -> FallingEdge<Self>
    where
        Self: Sized
, { ... }
fn and<M>(self, other: M) -> And<Self, M>
    where
        Self: Sized,
        M: Matcher
, { ... }
fn by_ref(&mut self) -> Ref<Self>
    where
        Self: Sized
, { ... } }

A predicate which can be fed a stream of Events and tell you whether they match a desired condition.

Individual Matchers may choose to return true more than once.

Any function which accepts a Event reference and returns a bool can be used as a Matcher.

fn assert_is_matcher(_: impl Matcher) {}

assert_is_matcher(|ev: &Event<'_>| true);

Required methods

fn matches_event(&mut self, event: &Event) -> bool

Evaluate this predicate against an event from an Event stream.

Loading content...

Provided methods

fn first_match<'src, I, E>(self, events: I) -> Option<usize> where
    Self: Sized,
    I: IntoIterator<Item = E> + 'src,
    E: Borrow<Event<'src>> + 'src, 

Find the index of the first Event which is matched by this predicate.

fn is_in<'src, I, E>(self, events: I) -> bool where
    I: IntoIterator<Item = E> + 'src,
    E: Borrow<Event<'src>>,
    Self: Sized

Checks whether this Matcher would match anything in a stream of Events.

Examples

let src = "# Heading\nsome text";
let matcher = markedit::exact_text("some text");

assert!(matcher.is_in(markedit::parse(src)));

fn then_start_of_next_line(self) -> StartOfNextLine<Self> where
    Self: Sized

Returns a Matcher which will wait until self matches, then return true at the start of the next top-level element.

fn fuse(self) -> OneShot<Self> where
    Self: Sized

Wraps self in a Matcher which will only ever return true once.

fn falling_edge(self) -> FallingEdge<Self> where
    Self: Sized

Get a Matcher which returns true when self goes from true to false.

fn and<M>(self, other: M) -> And<Self, M> where
    Self: Sized,
    M: Matcher

Get a Matcher which matches when self and other both match.

fn by_ref(&mut self) -> Ref<Self> where
    Self: Sized

Borrows the Matcher , rather than consuming it.

This allows you to apply Matcher adaptors while retaining ownership of the original Matcher.

Loading content...

Implementors

impl Matcher for Always[src]

impl Matcher for Heading[src]

impl<'a, M> Matcher for Ref<'a, M> where
    M: Matcher
[src]

impl<F> Matcher for F where
    F: FnMut(&Event) -> bool
[src]

impl<L: Matcher, R: Matcher> Matcher for And<L, R>[src]

impl<M: Matcher> Matcher for FallingEdge<M>[src]

impl<M: Matcher> Matcher for OneShot<M>[src]

impl<M: Matcher> Matcher for StartOfNextLine<M>[src]

Loading content...