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§
Sourcefn match_str(s: &str) -> Option<Self>
fn match_str(s: &str) -> Option<Self>
Given a string, return Self if the string matches some element of Self.
Sourcefn get_matches(&self) -> Vec<String>
fn get_matches(&self) -> Vec<String>
Given an element of Self, return the corresponding strings as a vector.
Provided Methods§
Sourcefn match_prefix(s: &str) -> Option<(usize, Self)>
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.