Skip to main content

SourceView

Struct SourceView 

Source
pub struct SourceView<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> SourceView<'a>

Source

pub fn id(&self) -> SourceId

Source

pub fn path(&self) -> Option<&'a str>

Source

pub fn locale(&self) -> Option<&'a str>

Source

pub fn message_id(&self) -> Option<&'a str>

Source

pub fn base_offset(&self) -> u32

Source

pub fn text(&self) -> Option<&'a str>

Snapshot-embedded source text bytes, if include_source_text was used during encoding.

Source

pub fn source_slice(&self, span: Span) -> Result<&'a str, SourceTextUnavailable>

Slice the snapshot-embedded source text by span, returning an explicit SourceTextUnavailable rather than None so callers can distinguish “source text not encoded” from “span out of bounds” — see design/003 §“Source Section”.

span is interpreted as a zero-based byte offset into the snapshot-embedded text, matching the spans returned by NodeView::span / TokenView::span / TriviaView::span / DiagnosticRecordView::span / DiagnosticLabelView::span. SourceView::base_offset is metadata (the file offset where the embedded substring starts in the original source) and is intentionally NOT subtracted here. Absolute file positions are base_offset + span_start / base_offset + span_end; callers that already hold an absolute span must subtract base_offset themselves before calling source_slice.

Returns Err(SourceTextUnavailable::NotIncluded) when the snapshot was produced with include_source_text = false (text source ref is the canonical NONE_REF sentinel). Returns Err(SourceTextUnavailable::SpanOutOfBounds) when span extends past the encoded text, when span.start > span.end, or when either endpoint lands inside a multibyte UTF-8 scalar.

Source

pub fn source_slice_with_external_text( &self, span: Span, external_source_text: &'a str, ) -> Result<&'a str, SourceTextUnavailable>

Slice source text by span, falling back to caller-provided external text when the snapshot was encoded with include_source_text = false.

The external text is explicit rather than looked up through a SourceStore: snapshot SourceIds are local to the emitted snapshot and do not have to match Phase 1 SourceStore ids. When snapshot-embedded text exists, it is preferred so this method has the same behaviour as Self::source_slice.

Trait Implementations§

Source§

impl<'a> Clone for SourceView<'a>

Source§

fn clone(&self) -> SourceView<'a>

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<'a> Copy for SourceView<'a>

Source§

impl<'a> Debug for SourceView<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SourceView<'a>

§

impl<'a> RefUnwindSafe for SourceView<'a>

§

impl<'a> Send for SourceView<'a>

§

impl<'a> Sync for SourceView<'a>

§

impl<'a> Unpin for SourceView<'a>

§

impl<'a> UnsafeUnpin for SourceView<'a>

§

impl<'a> UnwindSafe for SourceView<'a>

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.