pub trait SpanLike: Clone {
// Required methods
fn start(&self) -> usize;
fn end(&self) -> usize;
fn new(start: usize, end: usize) -> Self;
fn call_site() -> Self;
// Provided methods
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn join(&self, other: &Self) -> Self { ... }
}Expand description
A span representing a source location range.
Spans track the byte offsets of tokens and AST nodes within source text.
All implementations must be Clone to support parser backtracking.
Required Methods§
Provided Methods§
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the length of this span.
§Clamping Behavior
Uses saturating subtraction to compute end - start. If end < start
(an inverted span), this returns 0 rather than panicking or wrapping.
This ensures safe handling of malformed or sentinel span values.
fn is_empty(&self) -> bool
Sourcefn join(&self, other: &Self) -> Self
fn join(&self, other: &Self) -> Self
Join two spans into one covering both regions.
§Clamping Behavior
Uses min() for start and max() for end positions. No overflow checking
is performed since min/max operations cannot overflow. The result
spans from the earliest start to the latest end, regardless of whether
the input spans are inverted or disjoint.
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.