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
impl SourceSpan
Sourcepub const UNKNOWN: Self
pub const UNKNOWN: Self
A sentinel SourceSpan that indicates the span is unknown/invalid
Sourcepub fn new<B>(source_id: SourceId, range: Range<B>) -> Self
pub fn new<B>(source_id: SourceId, range: Range<B>) -> Self
Creates a new SourceSpan from the given range.
Sourcepub fn at(source_id: SourceId, offset: impl Into<ByteIndex>) -> Self
pub fn at(source_id: SourceId, offset: impl Into<ByteIndex>) -> Self
Creates a new SourceSpan for a specific offset.
Sourcepub fn try_from_range(
source_id: SourceId,
range: Range<usize>,
) -> Result<Self, InvalidByteIndexRange>
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.
Sourcepub const fn is_unknown(&self) -> bool
pub const fn is_unknown(&self) -> bool
Returns true
if this SourceSpan represents the unknown span
Sourcepub fn set_source_id(&mut self, id: SourceId)
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.
Sourcepub fn start(&self) -> ByteIndex
pub fn start(&self) -> ByteIndex
Gets the offset in bytes corresponding to the start of this span (inclusive).
Sourcepub fn end(&self) -> ByteIndex
pub fn end(&self) -> ByteIndex
Gets the offset in bytes corresponding to the end of this span (exclusive).
Sourcepub fn into_range(self) -> Range<u32>
pub fn into_range(self) -> Range<u32>
Converts this span into a Range<u32>
.
Sourcepub fn into_slice_index(self) -> Range<usize>
pub fn into_slice_index(self) -> Range<usize>
Converts this span into a Range<usize>
.
Trait Implementations§
Source§impl Clone for SourceSpan
impl Clone for SourceSpan
Source§fn clone(&self) -> SourceSpan
fn clone(&self) -> SourceSpan
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SourceSpan
impl Debug for SourceSpan
Source§impl Default for SourceSpan
impl Default for SourceSpan
Source§fn default() -> SourceSpan
fn default() -> SourceSpan
Source§impl Deserializable for SourceSpan
impl Deserializable for SourceSpan
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§impl<'de> Deserialize<'de> for SourceSpan
impl<'de> Deserialize<'de> for SourceSpan
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<SourceSpan> for Range<u32>
impl From<SourceSpan> for Range<u32>
Source§fn from(span: SourceSpan) -> Self
fn from(span: SourceSpan) -> Self
Source§impl From<SourceSpan> for Range<usize>
impl From<SourceSpan> for Range<usize>
Source§fn from(span: SourceSpan) -> Self
fn from(span: SourceSpan) -> Self
Source§impl From<SourceSpan> for SourceSpan
impl From<SourceSpan> for SourceSpan
Source§fn from(span: SourceSpan) -> Self
fn from(span: SourceSpan) -> Self
Source§impl Hash for SourceSpan
impl Hash for SourceSpan
Source§impl Index<SourceSpan> for [u8]
impl Index<SourceSpan> for [u8]
Source§impl Ord for SourceSpan
impl Ord for SourceSpan
Source§fn cmp(&self, other: &SourceSpan) -> Ordering
fn cmp(&self, other: &SourceSpan) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for SourceSpan
impl PartialEq for SourceSpan
Source§impl PartialOrd for SourceSpan
impl PartialOrd for SourceSpan
Source§impl RangeBounds<ByteIndex> for SourceSpan
impl RangeBounds<ByteIndex> for SourceSpan
Source§impl Serializable for SourceSpan
impl Serializable for SourceSpan
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self
into bytes and writes these bytes into the target
.