Struct SourceSpan
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§
§impl SourceSpan
impl SourceSpan
pub const UNKNOWN: SourceSpan
pub const UNKNOWN: SourceSpan
A sentinel SourceSpan that indicates the span is unknown/invalid
pub const SYNTHETIC: SourceSpan
pub const SYNTHETIC: SourceSpan
A sentinel SourceSpan that indicates compiler-generated/synthetic code
This is used to distinguish between:
- UNKNOWN: debug info missing or failed to parse from DWARF
- SYNTHETIC: compiler-generated code that doesn’t correspond to any user source
pub fn new<B>(source_id: SourceId, range: Range<B>) -> SourceSpanwhere
B: Into<ByteIndex>,
pub fn new<B>(source_id: SourceId, range: Range<B>) -> SourceSpanwhere
B: Into<ByteIndex>,
Creates a new SourceSpan from the given range.
pub fn at(source_id: SourceId, offset: impl Into<ByteIndex>) -> SourceSpan
pub fn at(source_id: SourceId, offset: impl Into<ByteIndex>) -> SourceSpan
Creates a new SourceSpan for a specific offset.
pub fn try_from_range(
source_id: SourceId,
range: Range<usize>,
) -> Result<SourceSpan, InvalidByteIndexRange>
pub fn try_from_range( source_id: SourceId, range: Range<usize>, ) -> Result<SourceSpan, InvalidByteIndexRange>
Try to create a new SourceSpan from the given range with usize bounds.
pub const fn is_unknown(&self) -> bool
pub const fn is_unknown(&self) -> bool
Returns true if this SourceSpan represents the unknown span
pub const fn is_synthetic(&self) -> bool
pub const fn is_synthetic(&self) -> bool
Returns true if this SourceSpan represents synthetic/compiler-generated code
pub 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.
pub fn start(&self) -> ByteIndex
pub fn start(&self) -> ByteIndex
Gets the offset in bytes corresponding to the start of this span (inclusive).
pub fn end(&self) -> ByteIndex
pub fn end(&self) -> ByteIndex
Gets the offset in bytes corresponding to the end of this span (exclusive).
pub fn into_range(self) -> Range<u32>
pub fn into_range(self) -> Range<u32>
Converts this span into a Range<u32>.
pub fn into_slice_index(self) -> Range<usize>
pub fn into_slice_index(self) -> Range<usize>
Converts this span into a Range<usize>.
Trait Implementations§
§impl Clone for SourceSpan
impl Clone for SourceSpan
§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 more§impl Debug for SourceSpan
impl Debug for SourceSpan
§impl Default for SourceSpan
impl Default for SourceSpan
§fn default() -> SourceSpan
fn default() -> SourceSpan
§impl Deserializable for SourceSpan
impl Deserializable for SourceSpan
§fn read_from<R>(source: &mut R) -> Result<SourceSpan, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<SourceSpan, DeserializationError>where
R: ByteReader,
source, attempts to deserialize these bytes
into Self, and returns the result. Read more§fn min_serialized_size() -> usize
fn min_serialized_size() -> usize
§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
§fn read_from_bytes_with_budget(
bytes: &[u8],
budget: usize,
) -> Result<Self, DeserializationError>
fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>
Self from bytes with a byte budget limit. Read more§impl<'de> Deserialize<'de> for SourceSpan
impl<'de> Deserialize<'de> for SourceSpan
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SourceSpan, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SourceSpan, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl From<Range<ByteIndex>> for SourceSpan
impl From<Range<ByteIndex>> for SourceSpan
§fn from(range: Range<ByteIndex>) -> SourceSpan
fn from(range: Range<ByteIndex>) -> SourceSpan
§impl From<Range<u32>> for SourceSpan
impl From<Range<u32>> for SourceSpan
§fn from(range: Range<u32>) -> SourceSpan
fn from(range: Range<u32>) -> SourceSpan
§impl Hash for SourceSpan
impl Hash for SourceSpan
§impl Index<SourceSpan> for [u8]
impl Index<SourceSpan> for [u8]
§impl Ord for SourceSpan
impl Ord for SourceSpan
§impl PartialEq for SourceSpan
impl PartialEq for SourceSpan
§impl PartialOrd for SourceSpan
impl PartialOrd for SourceSpan
§impl RangeBounds<ByteIndex> for SourceSpan
impl RangeBounds<ByteIndex> for SourceSpan
§impl Serializable for SourceSpan
impl Serializable for SourceSpan
§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self into bytes and writes these bytes into the target.§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
§impl Serialize for SourceSpan
impl Serialize for SourceSpan
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
§impl Spanned for SourceSpan
impl Spanned for SourceSpan
fn span(&self) -> SourceSpan
impl Copy for SourceSpan
impl Eq for SourceSpan
impl StructuralPartialEq for SourceSpan
Auto Trait Implementations§
impl Freeze for SourceSpan
impl RefUnwindSafe for SourceSpan
impl Send for SourceSpan
impl Sync for SourceSpan
impl Unpin for SourceSpan
impl UnsafeUnpin for SourceSpan
impl UnwindSafe for SourceSpan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more