Skip to main content

HasSpan

Trait HasSpan 

Source
pub trait HasSpan {
    // Required method
    fn span(&self) -> Span;
}
Expand description

Provides a token’s source span for diagnostics.

§Examples

use cel_parser::lex_lexer::HasSpan;

let input: proc_macro2::TokenStream = "name".parse()?;
let token = input.into_iter().next().unwrap();
assert_eq!(HasSpan::span(&token).source_text().as_deref(), Some("name"));

Required Methods§

Source

fn span(&self) -> Span

Returns the source span associated with this token.

§Examples
use cel_parser::lex_lexer::HasSpan;

let input: proc_macro2::TokenStream = "42".parse()?;
let token = input.into_iter().next().unwrap();
assert_eq!(HasSpan::span(&token).source_text().as_deref(), Some("42"));

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl HasSpan for TokenTree

Source§

fn span(&self) -> Span

Returns the source span of any token-tree variant.

Implementors§