Struct TokenMatch

Source
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>

Source

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(_)));
Source

pub fn contains_marker<M>(&'a self, marker: M) -> bool
where M: Hash,

Returns true if the TokenMatch or any of its descendents contain the given marker.

Returns false if the marker is not present.

Source

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.

Source

pub fn find_markers<'b, M>( &'a self, markers: &'b [M], ) -> impl Iterator<Item = &'a TokenMatch<'a>> + 'b
where M: Hash, 'a: 'b,

Iterate through all TokenMatch objects in the tree with a given set of markers.

Source

pub fn is_marked_with<M>(&self, marker: M) -> bool
where M: Hash,

Returns true if the root-level token has the given marker.

Returns false if it does not.

Source

pub fn meta_phrase(&self) -> Option<&str>

Source

pub fn meta_record(&self) -> Option<&Record>

Source

pub fn meta_sequence(&self) -> Option<&[TokenMatch<'a>]>

Source

pub fn meta_single(&self) -> Option<&TokenMatch<'a>>

Trait Implementations§

Source§

impl<'a> Clone for TokenMatch<'a>

Source§

fn clone(&self) -> TokenMatch<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for TokenMatch<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Token> for TokenMatch<'a>

Source§

fn from(input: &'a Token) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<TokenMatch<'a>> for MatchMeta<'a>

Source§

fn from(input: TokenMatch<'a>) -> MatchMeta<'a>

Converts to this type from the input type.
Source§

impl<'a> PartialEq for TokenMatch<'a>

Source§

fn eq(&self, other: &TokenMatch<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for TokenMatch<'a>

Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V