#[repr(C)]pub struct ByteSpan {
pub start: u32,
pub end: u32,
}Expand description
A compact source span representing a half-open byte range [start, end).
This is the primary span type stored on all tokens, AST nodes, and parse
errors. It is 8 bytes, Copy, and #[repr(C)] for predictable layout.
ByteSpan does not carry line/column/file information — those are
resolved on demand via SourceMap::resolve_span().
§Indexing Convention
Both start and end are 0-based byte offsets from the beginning of the
source text. The range is half-open: start is the byte offset of the
first character, and end is the byte offset immediately after the last
character.
Fields§
§start: u32Byte offset of the first character (inclusive).
end: u32Byte offset immediately after the last character (exclusive).
Implementations§
Source§impl ByteSpan
impl ByteSpan
Sourcepub fn new(start: u32, end: u32) -> Self
pub fn new(start: u32, end: u32) -> Self
Creates a new ByteSpan from start (inclusive) and end (exclusive)
byte offsets.
Sourcepub fn empty_at(offset: u32) -> Self
pub fn empty_at(offset: u32) -> Self
Creates an empty span at the given byte offset.
Useful for representing zero-width positions (e.g., EOF).
Sourcepub fn merge(self, other: ByteSpan) -> ByteSpan
pub fn merge(self, other: ByteSpan) -> ByteSpan
Creates a span that covers both self and other.
The resulting span starts at the minimum start and ends at the maximum end of the two spans.
Sourcepub fn resolve(&self, source_map: &SourceMap<'_>) -> Option<SourceSpan>
pub fn resolve(&self, source_map: &SourceMap<'_>) -> Option<SourceSpan>
Resolves this byte span to a SourceSpan with
line/column positions using the given SourceMap.
Returns None if the byte offsets cannot be resolved.
Convenience wrapper for
SourceMap::resolve_span().