SourceSpan

Struct SourceSpan 

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

This represents a span of bytes in a Miden Assembly source file.

It is compact, using only 8 bytes to represent the full span. This does, however, come at the tradeoff of only supporting source files of up to 2^32 bytes.

This type is produced by the lexer and carried through parsing. It can be converted into a line/column range as well, if needed.

This representation is more convenient to produce, and allows showing source spans in error messages, whereas line/column information is useful at a glance in debug output, it is harder to produce nice errors with it compared to this representation.

Implementations§

Source§

impl SourceSpan

Source

pub const UNKNOWN: Self

A sentinel SourceSpan that indicates the span is unknown/invalid

Source

pub fn new<B>(source_id: SourceId, range: Range<B>) -> Self
where B: Into<ByteIndex>,

Creates a new SourceSpan from the given range.

Source

pub fn at(source_id: SourceId, offset: impl Into<ByteIndex>) -> Self

Creates a new SourceSpan for a specific offset.

Source

pub fn try_from_range( source_id: SourceId, range: Range<usize>, ) -> Result<Self, InvalidByteIndexRange>

Try to create a new SourceSpan from the given range with usize bounds.

Source

pub const fn is_unknown(&self) -> bool

Returns true if this SourceSpan represents the unknown span

Source

pub fn source_id(&self) -> SourceId

Get the SourceId associated with this source span

Source

pub fn set_source_id(&mut self, id: SourceId)

Manually set the SourceId associated with this source span

This is useful in cases where the range of the span is known, but the source id itself is not available yet, due to scope or some other limitation. In such cases you might wish to visit parsed objects once the source id is available, and update all of their spans accordingly.

Source

pub fn start(&self) -> ByteIndex

Gets the offset in bytes corresponding to the start of this span (inclusive).

Source

pub fn end(&self) -> ByteIndex

Gets the offset in bytes corresponding to the end of this span (exclusive).

Source

pub fn len(&self) -> usize

Gets the length of this span in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if this span is empty.

Source

pub fn into_range(self) -> Range<u32>

Converts this span into a Range<u32>.

Source

pub fn into_slice_index(self) -> Range<usize>

Converts this span into a Range<usize>.

Trait Implementations§

Source§

impl Clone for SourceSpan

Source§

fn clone(&self) -> SourceSpan

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 SourceSpan

Source§

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

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

impl Default for SourceSpan

Source§

fn default() -> SourceSpan

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

impl Deserializable for SourceSpan

Source§

fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
Source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
Source§

impl<'de> Deserialize<'de> for SourceSpan

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 From<Range<ByteIndex>> for SourceSpan

Source§

fn from(range: Range<ByteIndex>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<u32>> for SourceSpan

Source§

fn from(range: Range<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<SourceSpan> for Range<u32>

Source§

fn from(span: SourceSpan) -> Self

Converts to this type from the input type.
Source§

impl From<SourceSpan> for Range<usize>

Source§

fn from(span: SourceSpan) -> Self

Converts to this type from the input type.
Source§

impl From<SourceSpan> for SourceSpan

Source§

fn from(span: SourceSpan) -> Self

Converts to this type from the input type.
Source§

impl Hash for SourceSpan

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 Index<SourceSpan> for [u8]

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: SourceSpan) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Ord for SourceSpan

Source§

fn cmp(&self, other: &SourceSpan) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SourceSpan

Source§

fn eq(&self, other: &SourceSpan) -> 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 PartialOrd for SourceSpan

Source§

fn partial_cmp(&self, other: &SourceSpan) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl RangeBounds<ByteIndex> for SourceSpan

Source§

fn start_bound(&self) -> Bound<&ByteIndex>

Start index bound. Read more
Source§

fn end_bound(&self) -> Bound<&ByteIndex>

End index bound. Read more
1.35.0 · Source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
Source§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl Serializable for SourceSpan

Source§

fn write_into<W: ByteWriter>(&self, target: &mut W)

Serializes self into bytes and writes these bytes into the target.
Source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
Source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
Source§

impl Serialize for SourceSpan

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Spanned for SourceSpan

Source§

impl Copy for SourceSpan

Source§

impl Eq for SourceSpan

Source§

impl StructuralPartialEq for SourceSpan

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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