pub struct Span {
pub start: Position,
pub end: Position,
pub start_offset: usize,
pub end_offset: usize,
}Expand description
A span in source text, covering a range between two positions.
Spans are used to indicate the start and end positions of parsed elements. They include both line/column positions and byte offsets for flexible use.
§Byte Offset Semantics
Byte offsets use exclusive end semantics (like Rust ranges):
start_offset..end_offsetcovers the half-open range[start, end)- Use
source[start_offset..end_offset]to slice the spanned text
§Position Semantics
Line and column positions are 1-indexed (the first line is line 1, the first column is column 1). The end position points to the last character in the span (inclusive for display purposes).
§Synthetic Spans
Spans created by Span::synthetic() have line: 0 to distinguish them
from real source positions. Use is_synthetic() to check.
Fields§
§start: PositionThe start position (line and column, 1-indexed).
end: PositionThe end position (line and column, 1-indexed).
start_offset: usizeThe start byte offset in the source (0-indexed, inclusive).
end_offset: usizeThe end byte offset in the source (0-indexed, exclusive).
Implementations§
Source§impl Span
impl Span
Sourcepub const fn synthetic() -> Self
pub const fn synthetic() -> Self
Create a synthetic span for values without source positions.
Uses line 0 to distinguish from real spans (which are 1-indexed).
This is useful when converting Value to Expr for deserialization.
Check with is_synthetic().
Sourcepub const fn is_synthetic(&self) -> bool
pub const fn is_synthetic(&self) -> bool
Returns true if this is a synthetic span (no source position).
Synthetic spans are created by Span::synthetic() for values
converted from Value to AST without original source positions.
They use line 0 to distinguish from real spans (which are 1-indexed).
Trait Implementations§
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.