pub struct Span { /* private fields */ }Expand description
A span within the source YAML document.
This structure provides location information in two forms:
- Character-based:
offsetandlencount Unicode scalar values. This matchesgranit-parser’s native reporting and is always present. - Byte-based:
byte_infocontains(byte_offset, byte_len)counting raw bytes (UTF-8 code units). These are only populated when parsing from string inputs (&str,String).
By default, offsets are stored internally as u32, which keeps the span compact and
supports YAML inputs up to 4 GiB for byte-based coordinates.
With the huge_documents feature, offsets are stored in a packed 48-bit representation.
Public getters still return u64, and values beyond 48 bits saturate instead of wrapping.
This keeps crate::Location compact enough to avoid inflating [crate::Error] as much
as a full u64-based layout would.
The maximum storage value is reserved for Span::UNKNOWN and unavailable byte info.
Implementations§
Source§impl Span
impl Span
Sourcepub const fn new(offset: u64, len: u64) -> Self
pub const fn new(offset: u64, len: u64) -> Self
Construct a span from character-based offset and length.
Values that exceed the active non-sentinel storage range are saturated.
Sourcepub const fn with_byte_info(self, byte_offset: u64, byte_len: u64) -> Self
pub const fn with_byte_info(self, byte_offset: u64, byte_len: u64) -> Self
Attach byte-based offset and length information to the span.
Values that exceed the active non-sentinel storage range are saturated.
Sourcepub fn byte_offset(&self) -> Option<u64>
pub fn byte_offset(&self) -> Option<u64>
Returns the byte offset within the source YAML document.
Returns None if byte info is unavailable.
Sourcepub fn byte_len(&self) -> Option<u64>
pub fn byte_len(&self) -> Option<u64>
Returns the byte length within the source YAML document.
Returns None if byte info is unavailable.