pub struct TokenMatch<'a> {
pub token: &'a Token,
pub match_meta: MatchMeta<'a>,
}
Fields§
§token: &'a Token
§match_meta: MatchMeta<'a>
Implementations§
Source§impl<'a> TokenMatch<'a>
impl<'a> TokenMatch<'a>
Sourcepub fn new(token: &'a Token, match_meta: impl Into<MatchMeta<'a>>) -> Self
pub fn new(token: &'a Token, match_meta: impl Into<MatchMeta<'a>>) -> Self
Creates a new TokenMatch
object containing a reference to the Token
that was matched.
match_meta
is typically not passed directly, but rather via the Into<T>
trait. In the
case where match_meta
is MatchMeta::None
, TokenMatch::from(&token)
is preferred.
§Examples
let token = any_word();
// Use ::from to create a TokenMatch with no metadata.
let token_match = TokenMatch::from(&token);
assert_eq!(MatchMeta::None, token_match.match_meta);
// Provide a &str for MatchMeta::Phrase.
let token_match = TokenMatch::new(&token, "word");
assert_eq!(MatchMeta::Phrase("word"), token_match.match_meta);
// Provide a Record for MatchMeta::Record.
let record = app_meta.repository.get_by_name("Odysseus").await.unwrap();
let token_match = TokenMatch::new(&token, record);
assert!(matches!(token_match.match_meta, MatchMeta::Record(_)));
// Provide a Vec<TokenMatch> for MatchMeta::Sequence.
let sequence_token = sequence([any_word()]);
let token_match = TokenMatch::new(&sequence_token, vec![TokenMatch::from(&token)]);
assert!(matches!(token_match.match_meta, MatchMeta::Sequence(_)));
// Provide a TokenMatch for MatchMeta::Single.
let optional_token = optional(any_word());
let token_match = TokenMatch::new(&optional_token, TokenMatch::from(&token));
assert!(matches!(token_match.match_meta, MatchMeta::Single(_)));
Sourcepub fn contains_marker<M>(&'a self, marker: M) -> boolwhere
M: Hash,
pub fn contains_marker<M>(&'a self, marker: M) -> boolwhere
M: Hash,
Returns true
if the TokenMatch
or any of its descendents contain the given marker.
Returns false
if the marker is not present.
Sourcepub fn find_marker<M>(&'a self, marker: M) -> Option<&'a TokenMatch<'a>>where
M: Hash,
pub fn find_marker<M>(&'a self, marker: M) -> Option<&'a TokenMatch<'a>>where
M: Hash,
Returns the first TokenMatch
with a given marker in the token tree.
Returns None
if the patterns doesn’t match.
Sourcepub fn find_markers<'b, M>(
&'a self,
markers: &'b [M],
) -> impl Iterator<Item = &'a TokenMatch<'a>> + 'bwhere
M: Hash,
'a: 'b,
pub fn find_markers<'b, M>(
&'a self,
markers: &'b [M],
) -> impl Iterator<Item = &'a TokenMatch<'a>> + 'bwhere
M: Hash,
'a: 'b,
Iterate through all TokenMatch objects in the tree with a given set of markers.
Sourcepub fn is_marked_with<M>(&self, marker: M) -> boolwhere
M: Hash,
pub fn is_marked_with<M>(&self, marker: M) -> boolwhere
M: Hash,
Returns true
if the root-level token has the given marker
.
Returns false
if it does not.
pub fn meta_phrase(&self) -> Option<&str>
pub fn meta_record(&self) -> Option<&Record>
pub fn meta_sequence(&self) -> Option<&[TokenMatch<'a>]>
pub fn meta_single(&self) -> Option<&TokenMatch<'a>>
Trait Implementations§
Source§impl<'a> Clone for TokenMatch<'a>
impl<'a> Clone for TokenMatch<'a>
Source§fn clone(&self) -> TokenMatch<'a>
fn clone(&self) -> TokenMatch<'a>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'a> Debug for TokenMatch<'a>
impl<'a> Debug for TokenMatch<'a>
Source§impl<'a> From<&'a Token> for TokenMatch<'a>
impl<'a> From<&'a Token> for TokenMatch<'a>
Source§impl<'a> From<TokenMatch<'a>> for MatchMeta<'a>
impl<'a> From<TokenMatch<'a>> for MatchMeta<'a>
Source§fn from(input: TokenMatch<'a>) -> MatchMeta<'a>
fn from(input: TokenMatch<'a>) -> MatchMeta<'a>
Converts to this type from the input type.
Source§impl<'a> PartialEq for TokenMatch<'a>
impl<'a> PartialEq for TokenMatch<'a>
impl<'a> Eq for TokenMatch<'a>
impl<'a> StructuralPartialEq for TokenMatch<'a>
Auto Trait Implementations§
impl<'a> Freeze for TokenMatch<'a>
impl<'a> RefUnwindSafe for TokenMatch<'a>
impl<'a> Send for TokenMatch<'a>
impl<'a> Sync for TokenMatch<'a>
impl<'a> Unpin for TokenMatch<'a>
impl<'a> UnwindSafe for TokenMatch<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more