SpanLike

Trait SpanLike 

Source
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§

Source

fn start(&self) -> usize

Returns the start byte offset.

Source

fn end(&self) -> usize

Returns the end byte offset (exclusive).

Source

fn new(start: usize, end: usize) -> Self

Creates a new span from start and end offsets.

Source

fn call_site() -> Self

Returns a synthetic span for generated code.

Provided Methods§

Source

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.

Source

fn is_empty(&self) -> bool

Source

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.

Implementors§