pub trait SpanRanged {
// Required method
fn span_range(&self) -> Range<Span> ⓘ;
// Provided method
fn span_joined(&self) -> Option<Span> { ... }
}Expand description
Returns the Range<Span> from the start to the end of
multi-token structures.
start and end can be the same when called on single Tokens or Span.
Due to compiler limitations, it is currently not possible to implement
SpanRanged for T: ToTokens, therefor there is
to_tokens_span_range().
For types that either implement SpanRanged or ToTokens (but
NOT both) the span_range! macro can be used as well.
§Motivation
This is superior to a normal Span (at least until Span::join works
on stable), because it leads to better error messages:
Given the following expression
let a = |something: usize| something;ErrorMessage::new(first_pipe_span, "error message")
would result in something like
error: error message
let a = |something: usize| something;
^While ErrorMessage::new(first_pipe_span..something_span, "error message") would improve the error message to:
error: error message
let a = |something: usize| something;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^Required Methods§
Provided Methods§
Sourcefn span_joined(&self) -> Option<Span>
fn span_joined(&self) -> Option<Span>
Returns Self::span_range as a single span if possible, currently
only possible on nightly. more