pub trait HasSpan<'ast>: Sealed {
// Required method
fn span(&self) -> &Span<'ast>;
}
Expand description
A trait for types, that provide a Span
. It is implemented for all
AST nodes, Span
itself, and for references to them as well.
This gives you the ability to invoke functions that take impl HasSpan
in many different ways. Just choose the one that fits your use case the best.
fn takes_span<'ast>(span: impl HasSpan<'ast>) {
let span: &Span<'ast> = span.span();
// ...
}
fn visit_expr(expr: ExprKind<'_>) {
takes_span(expr);
takes_span(&expr);
takes_span(expr.span());
takes_span(&expr.span());
}