pub struct SourceView<'a> { /* private fields */ }Implementations§
Source§impl<'a> SourceView<'a>
impl<'a> SourceView<'a>
pub fn id(&self) -> SourceId
pub fn path(&self) -> Option<&'a str>
pub fn locale(&self) -> Option<&'a str>
pub fn message_id(&self) -> Option<&'a str>
pub fn base_offset(&self) -> u32
Sourcepub fn text(&self) -> Option<&'a str>
pub fn text(&self) -> Option<&'a str>
Snapshot-embedded source text bytes, if include_source_text
was used during encoding.
Sourcepub fn source_slice(&self, span: Span) -> Result<&'a str, SourceTextUnavailable>
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.
Sourcepub fn source_slice_with_external_text(
&self,
span: Span,
external_source_text: &'a str,
) -> Result<&'a str, SourceTextUnavailable>
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>
impl<'a> Clone for SourceView<'a>
Source§fn clone(&self) -> SourceView<'a>
fn clone(&self) -> SourceView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more