Skip to main content

TokenType

Trait TokenType 

Source
pub trait TokenType:
    Copy
    + Eq
    + Hash
    + Send
    + Sync
    + Debug
    + Serialize
    + for<'de> Deserialize<'de> {
    type Role: TokenRole;

    const END_OF_STREAM: Self;

    // Required method
    fn role(&self) -> Self::Role;

    // Provided methods
    fn is_role(&self, role: Self::Role) -> bool { ... }
    fn is_universal(&self, role: UniversalTokenRole) -> bool { ... }
    fn is_comment(&self) -> bool { ... }
    fn is_whitespace(&self) -> bool { ... }
    fn is_error(&self) -> bool { ... }
    fn is_ignored(&self) -> bool { ... }
    fn is_end_of_stream(&self) -> bool { ... }
}
Expand description

A trait for types that represent a token’s kind in a specific language.

Required Associated Constants§

Source

const END_OF_STREAM: Self

A constant representing the end of the input stream.

Required Associated Types§

Source

type Role: TokenRole

The associated role type for this token kind.

Required Methods§

Source

fn role(&self) -> Self::Role

Returns the general syntactic role of this token.

Provided Methods§

Source

fn is_role(&self, role: Self::Role) -> bool

Returns true if this token matches the specified language-specific role.

Source

fn is_universal(&self, role: UniversalTokenRole) -> bool

Returns true if this token matches the specified universal role.

Source

fn is_comment(&self) -> bool

Returns true if this token represents a comment.

Source

fn is_whitespace(&self) -> bool

Returns true if this token represents whitespace.

Source

fn is_error(&self) -> bool

Returns true if this token represents an error condition.

Source

fn is_ignored(&self) -> bool

Returns true if this token represents trivia (whitespace, comments, etc.).

Source

fn is_end_of_stream(&self) -> bool

Returns true if this token represents the end of the input stream.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§