pub struct Token {
pub kind: TokenKind,
pub span: Span,
}
Fields§
§kind: TokenKind
§span: Span
Implementations§
source§impl Token
impl Token
pub fn new(kind: TokenKind, span: Span) -> Self
sourcepub fn from_ast_ident(ident: Ident) -> Self
pub fn from_ast_ident(ident: Ident) -> Self
Recovers a Token
from an Ident
. This creates a raw identifier if necessary.
sourcepub fn uninterpolated_span(&self) -> Span
pub fn uninterpolated_span(&self) -> Span
For interpolated tokens, returns a span of the fragment to which the interpolated token refers. For all other tokens this is just a regular span. It is particularly important to use this for identifiers and lifetimes for which spans affect name resolution and edition checks. Note that keywords are also identifiers, so they should use this if they keep spans or perform edition checks.
pub fn is_range_separator(&self) -> bool
pub fn is_punct(&self) -> bool
pub fn is_like_plus(&self) -> bool
sourcepub fn can_begin_expr(&self) -> bool
pub fn can_begin_expr(&self) -> bool
Returns true
if the token can appear at the start of an expression.
sourcepub fn can_begin_pattern(&self) -> bool
pub fn can_begin_pattern(&self) -> bool
Returns true
if the token can appear at the start of a pattern.
Shamelessly borrowed from can_begin_expr
, only used for diagnostics right now.
sourcepub fn can_begin_type(&self) -> bool
pub fn can_begin_type(&self) -> bool
Returns true
if the token can appear at the start of a type.
sourcepub fn can_begin_const_arg(&self) -> bool
pub fn can_begin_const_arg(&self) -> bool
Returns true
if the token can appear at the start of a const param.
sourcepub fn can_begin_item(&self) -> bool
pub fn can_begin_item(&self) -> bool
Returns true
if the token can appear at the start of an item.
sourcepub fn can_begin_literal_maybe_minus(&self) -> bool
pub fn can_begin_literal_maybe_minus(&self) -> bool
Returns true
if the token is any literal, a minus (which can prefix a literal,
for example a ‘-42’, or one of the boolean idents).
In other words, would this token be a valid start of parse_literal_maybe_minus
?
Keep this in sync with and Lit::from_token
, excluding unary negation.
pub fn can_begin_string_literal(&self) -> bool
sourcepub fn uninterpolate(&self) -> Cow<'_, Token>
pub fn uninterpolate(&self) -> Cow<'_, Token>
A convenience function for matching on identifiers during parsing.
Turns interpolated identifier ($i: ident
) or lifetime ($l: lifetime
) token
into the regular identifier or lifetime token it refers to,
otherwise returns the original token.
sourcepub fn ident(&self) -> Option<(Ident, IdentIsRaw)>
pub fn ident(&self) -> Option<(Ident, IdentIsRaw)>
Returns an identifier if this token is an identifier.
sourcepub fn lifetime(&self) -> Option<Ident>
pub fn lifetime(&self) -> Option<Ident>
Returns a lifetime identifier if this token is a lifetime.
sourcepub fn is_lifetime(&self) -> bool
pub fn is_lifetime(&self) -> bool
Returns true
if the token is a lifetime.
sourcepub fn is_ident_named(&self, name: Symbol) -> bool
pub fn is_ident_named(&self, name: Symbol) -> bool
Returns true
if the token is an identifier whose name is the given
string slice.
sourcefn is_whole_path(&self) -> bool
fn is_whole_path(&self) -> bool
Returns true
if the token is an interpolated path.
sourcepub fn is_whole_expr(&self) -> bool
pub fn is_whole_expr(&self) -> bool
Is this a pre-parsed expression dropped into the token stream (which happens while parsing the result of macro expansion)?
sourcepub fn is_whole_block(&self) -> bool
pub fn is_whole_block(&self) -> bool
Is the token an interpolated block ($b:block
)?
sourcepub fn is_mutability(&self) -> bool
pub fn is_mutability(&self) -> bool
Returns true
if the token is either the mut
or const
keyword.
pub fn is_qpath_start(&self) -> bool
pub fn is_path_start(&self) -> bool
sourcepub fn is_keyword(&self, kw: Symbol) -> bool
pub fn is_keyword(&self, kw: Symbol) -> bool
Returns true
if the token is a given keyword, kw
.
sourcepub fn is_keyword_case(&self, kw: Symbol, case: Case) -> bool
pub fn is_keyword_case(&self, kw: Symbol, case: Case) -> bool
Returns true
if the token is a given keyword, kw
or if case
is Insensitive
and this token is an identifier equal to kw
ignoring the case.
pub fn is_path_segment_keyword(&self) -> bool
sourcepub fn is_special_ident(&self) -> bool
pub fn is_special_ident(&self) -> bool
Returns true for reserved identifiers used internally for elided lifetimes, unnamed method parameters, crate root module, error recovery etc.
sourcepub fn is_used_keyword(&self) -> bool
pub fn is_used_keyword(&self) -> bool
Returns true
if the token is a keyword used in the language.
sourcepub fn is_unused_keyword(&self) -> bool
pub fn is_unused_keyword(&self) -> bool
Returns true
if the token is a keyword reserved for possible future use.
sourcepub fn is_reserved_ident(&self) -> bool
pub fn is_reserved_ident(&self) -> bool
Returns true
if the token is either a special identifier or a keyword.
sourcepub fn is_bool_lit(&self) -> bool
pub fn is_bool_lit(&self) -> bool
Returns true
if the token is the identifier true
or false
.
pub fn is_numeric_lit(&self) -> bool
sourcepub fn is_integer_lit(&self) -> bool
pub fn is_integer_lit(&self) -> bool
Returns true
if the token is the integer literal.
sourcepub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool
Returns true
if the token is a non-raw identifier for which pred
holds.
pub fn glue(&self, joint: &Token) -> Option<Token>
Trait Implementations§
source§impl<__CTX> HashStable<__CTX> for Tokenwhere
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for Tokenwhere
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
source§impl PartialEq<TokenKind> for Token
impl PartialEq<TokenKind> for Token
source§impl PartialEq for Token
impl PartialEq for Token
impl StructuralPartialEq for Token
Auto Trait Implementations§
impl DynSend for Token
impl DynSync for Token
impl Freeze for Token
impl !RefUnwindSafe for Token
impl !Send for Token
impl !Sync for Token
impl Unpin for Token
impl !UnwindSafe for Token
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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: 24 bytes