struct MatcherPos<'tt> {
    top_elts: &'tt [TokenTree],
    idx: usize,
    matches: Box<[Lrc<SmallVec<[NamedMatch; 1]>>]>,
    match_lo: usize,
    match_cur: usize,
    match_hi: usize,
    repetition: Option<MatcherPosRepetition<'tt>>,
    stack: SmallVec<[MatcherTtFrame<'tt>; 1]>,
}
Expand description

Represents a single “position” (aka “matcher position”, aka “item”), as described in the module documentation.

Fields

top_elts: &'tt [TokenTree]

The token or slice of tokens that make up the matcher. elts is short for “elements”.

idx: usize

The position of the “dot” in this matcher

matches: Box<[Lrc<SmallVec<[NamedMatch; 1]>>]>

For each named metavar in the matcher, we keep track of token trees matched against the metavar by the black box parser. In particular, there may be more than one match per metavar if we are in a repetition (each repetition matches each of the variables). Moreover, matchers and repetitions can be nested; the matches field is shared (hence the Rc) among all “nested” matchers. match_lo, match_cur, and match_hi keep track of the current position of the self matcher position in the shared matches list.

Also, note that while we are descending into a sequence, matchers are given their own matches vector. Only once we reach the end of a full repetition of the sequence do we add all bound matches from the submatcher into the shared top-level matches vector. If sep and up are Some, then matches is not the shared top-level list. Instead, if one wants the shared matches, one should use up.matches.

match_lo: usize

The position in matches corresponding to the first metavar in this matcher’s sequence of token trees. In other words, the first metavar in the first token of top_elts corresponds to matches[match_lo].

match_cur: usize

The position in matches corresponding to the metavar we are currently trying to match against the source token stream. match_lo <= match_cur <= match_hi.

match_hi: usize

Similar to match_lo except match_hi is the position in matches of the last metavar in this matcher.

repetition: Option<MatcherPosRepetition<'tt>>

This field is only used if we are matching a repetition.

stack: SmallVec<[MatcherTtFrame<'tt>; 1]>

Specifically used to “unzip” token trees. By “unzip”, we mean to unwrap the delimiters from a delimited token tree (e.g., something wrapped in ( )) or to get the contents of a doc comment…

When matching against matchers with nested delimited submatchers (e.g., pat ( pat ( .. ) pat ) pat), we need to keep track of the matchers we are descending into. This stack does that where the bottom of the stack is the outermost matcher. Also, throughout the comments, this “descent” is often referred to as “unzipping”…

Implementations

len Vecs (initially shared and empty) that will store matches of metavars.

Generates the top-level matcher position in which the “dot” is before the first token of the matcher ms.

Adds m as a named match for the idx-th metavar.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 112 bytes