Match

Trait Match 

Source
pub trait Match: Sized {
    // Required methods
    fn match_str(s: &str) -> Option<Self>;
    fn get_matches(&self) -> Vec<String>;

    // Provided method
    fn match_prefix(s: &str) -> Option<(usize, Self)> { ... }
}
Expand description

A trait that, when implemented for a type T, implements a method that, given a string, outputs a matching element of T if applicable. Also, whitespace and strings starting with whitespace can never be a match, as starting whitespace is always ignored by the parser.

Required Methods§

Source

fn match_str(s: &str) -> Option<Self>

Given a string, return Self if the string matches some element of Self.

Source

fn get_matches(&self) -> Vec<String>

Given an element of Self, return the corresponding strings as a vector.

Provided Methods§

Source

fn match_prefix(s: &str) -> Option<(usize, Self)>

Match a prefix of a given string against the string matches. Uses the conventional max-munch principle: if the string is "orange" and "o" and "or" are both matches, the method will return "or".

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Match for PropBinary

Source§

impl Match for PropUnary

Source§

impl Match for Atom

Source§

impl<B, U, A> Match for Symbol<B, U, A>
where B: Symbolic + Match, U: Symbolic + Match, A: Symbolic + Match,