Skip to main content

AstToken

Trait AstToken 

Source
pub trait AstToken: Sized {
    // Required methods
    fn can_cast(kind: SyntaxKind) -> bool;
    fn cast(token: SyntaxToken) -> Option<Self>;
    fn syntax(&self) -> &SyntaxToken;

    // Provided method
    fn text(&self) -> &str { ... }
}
Expand description

Typed wrapper around a SyntaxToken of a specific SyntaxKind. Like AstNode but for leaf tokens.

Required Methods§

Source

fn can_cast(kind: SyntaxKind) -> bool

Source

fn cast(token: SyntaxToken) -> Option<Self>

Source

fn syntax(&self) -> &SyntaxToken

Provided Methods§

Source

fn text(&self) -> &str

The raw token text (borrowed from the green tree, zero allocation). Tokens are always contiguous, so a &str slice is well-defined.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§