Skip to main content

Span

Struct Span 

Source
pub struct Span { /* private fields */ }
Expand description

A span within the source YAML document.

This structure provides location information in two forms:

  1. Character-based: offset and len count Unicode scalar values. This matches granit-parser’s native reporting and is always present.
  2. Byte-based: byte_info contains (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

Source

pub const UNKNOWN: Self

Sentinel span meaning “unknown”.

Source

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.

Source

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.

Source

pub fn offset(&self) -> u64

Returns the character offset within the source YAML document.

Source

pub fn len(&self) -> u64

Returns the character length within the source YAML document.

Source

pub fn byte_offset(&self) -> Option<u64>

Returns the byte offset within the source YAML document. Returns None if byte info is unavailable.

Source

pub fn byte_len(&self) -> Option<u64>

Returns the byte length within the source YAML document. Returns None if byte info is unavailable.

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Span

Source§

impl Debug for Span

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Span

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Span

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Span

Source§

impl Hash for Span

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Span

Source§

fn eq(&self, other: &Span) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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 UnsafeUnpin for Span

§

impl UnwindSafe for Span

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.