Skip to main content

ByteSpan

Struct ByteSpan 

Source
#[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: u32

Byte offset of the first character (inclusive).

§end: u32

Byte offset immediately after the last character (exclusive).

Implementations§

Source§

impl ByteSpan

Source

pub fn new(start: u32, end: u32) -> Self

Creates a new ByteSpan from start (inclusive) and end (exclusive) byte offsets.

Source

pub fn len(&self) -> u32

Returns the length of this span in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the span is empty (zero length).

Source

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).

Source

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.

Source

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().

Trait Implementations§

Source§

impl Clone for ByteSpan

Source§

fn clone(&self) -> ByteSpan

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ByteSpan

Source§

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

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

impl Default for ByteSpan

Source§

fn default() -> ByteSpan

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

impl Hash for ByteSpan

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 ByteSpan

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ByteSpan

Source§

impl Eq for ByteSpan

Source§

impl StructuralPartialEq for ByteSpan

Auto Trait Implementations§

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.