pub struct Token { /* private fields */ }Expand description
A single token.
This struct is written in such a way that it can be passed in registers.
The actual representation is TokenRepr, but it should not be accessed directly.
Implementations§
Source§impl Token
impl Token
Sourcepub fn from_ast_ident(ident: Ident) -> Token
pub fn from_ast_ident(ident: Ident) -> Token
Recovers a Token from an Ident.
Sourcepub fn ident(&self) -> Option<Ident>
pub fn ident(&self) -> Option<Ident>
Creates a new identifier if the kind is TokenKind::Ident.
Sourcepub fn lit(&self) -> Option<TokenLit>
pub fn lit(&self) -> Option<TokenLit>
Returns the literal if the kind is TokenKind::Literal.
Sourcepub fn lit_kind(&self) -> Option<TokenLitKind>
pub fn lit_kind(&self) -> Option<TokenLitKind>
Returns this token’s literal kind, if any.
Sourcepub fn comment(&self) -> Option<(bool, DocComment)>
pub fn comment(&self) -> Option<(bool, DocComment)>
Returns the comment if the kind is TokenKind::Comment, and whether it’s a doc-comment.
Sourcepub fn doc(&self) -> Option<DocComment>
pub fn doc(&self) -> Option<DocComment>
Returns the comment if the kind is TokenKind::Comment.
Does not check that is_doc is true.
Sourcepub fn as_unop(&self, is_postfix: bool) -> Option<UnOp>
pub fn as_unop(&self, is_postfix: bool) -> Option<UnOp>
Returns the token as a unary operator, if any.
Sourcepub fn as_binop_eq(&self) -> Option<BinOp>
pub fn as_binop_eq(&self) -> Option<BinOp>
Returns the token as a binary operator, if any.
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_any(&self, kws: &[Symbol]) -> bool
pub fn is_keyword_any(&self, kws: &[Symbol]) -> bool
Returns true if the token is any of the given keywords.
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, yul: bool) -> bool
pub fn is_reserved_ident(&self, yul: bool) -> bool
Returns true if the token is a keyword.
Sourcepub fn is_non_reserved_ident(&self, yul: bool) -> bool
pub fn is_non_reserved_ident(&self, yul: bool) -> bool
Returns true if the token is an identifier, but not a keyword.
Sourcepub fn is_elementary_type(&self) -> bool
pub fn is_elementary_type(&self) -> bool
Returns true if the token is an elementary type name.
Note that this does not include [u]fixedMxN types.
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.
Sourcepub fn is_numeric_lit(&self) -> bool
pub fn is_numeric_lit(&self) -> bool
Returns true if the token is a numeric literal.
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_rational_lit(&self) -> bool
pub fn is_rational_lit(&self) -> bool
Returns true if the token is the rational literal.
Sourcepub fn is_str_lit(&self) -> bool
pub fn is_str_lit(&self) -> bool
Returns true if the token is a string literal.
Sourcepub fn is_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool
pub fn is_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool
Returns true if the token is an identifier for which pred holds.
Sourcepub fn is_open_delim(&self, d: Delimiter) -> bool
pub fn is_open_delim(&self, d: Delimiter) -> bool
Returns true if the token is the given open delimiter.
Sourcepub fn is_close_delim(&self, d: Delimiter) -> bool
pub fn is_close_delim(&self, d: Delimiter) -> bool
Returns true if the token is the given close delimiter.
Sourcepub fn is_comment(&self) -> bool
pub fn is_comment(&self) -> bool
Returns true if the token is a normal comment (not a doc-comment).
Sourcepub fn is_comment_or_doc(&self) -> bool
pub fn is_comment_or_doc(&self) -> bool
Returns true if the token is a comment or doc-comment.
Sourcepub fn is_location_specifier(&self) -> bool
pub fn is_location_specifier(&self) -> bool
Returns true if the token is a location specifier.
Sourcepub fn is_mutability_specifier(&self) -> bool
pub fn is_mutability_specifier(&self) -> bool
Returns true if the token is a mutability specifier.
Sourcepub fn is_visibility_specifier(&self) -> bool
pub fn is_visibility_specifier(&self) -> bool
Returns true if the token is a visibility specifier.
Sourcepub fn full_description(&self) -> impl Display
pub fn full_description(&self) -> impl Display
Returns this token’s full description: {self.description()} '{self.kind}'.
Sourcepub fn description(self) -> Option<TokenDescription>
pub fn description(self) -> Option<TokenDescription>
Returns this token’s description, if any.
Trait Implementations§
impl Copy for Token
impl Eq for Token
Auto Trait Implementations§
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§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
fn equivalent(&self, key: &K) -> bool
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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<Q> ToOwnedEquivalent<<Q as ToOwned>::Owned> for Q
impl<Q> ToOwnedEquivalent<<Q as ToOwned>::Owned> for Q
fn to_owned_equivalent(&self) -> <Q as ToOwned>::Owned
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>
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: 16 bytes