pub struct SourceFileRef { /* private fields */ }
Expand description
A reference to a specific spanned region of a SourceFile, that provides access to the actual SourceFile, but scoped to the span it was created with.
This is useful in error types that implement miette::Diagnostic, as it contains all of the data necessary to render the source code being referenced, without a super::SourceManager on hand.
Implementations§
Source§impl SourceFileRef
impl SourceFileRef
Sourcepub fn new(file: Arc<SourceFile>, span: impl Into<Range<u32>>) -> Self
pub fn new(file: Arc<SourceFile>, span: impl Into<Range<u32>>) -> Self
Create a SourceFileRef from a SourceFile and desired span (in bytes)
The given span will be constrained to the bytes of file
, so a span that reaches out of
bounds will have its end bound set to the last byte of the file.
Sourcepub fn source_file(&self) -> Arc<SourceFile>
pub fn source_file(&self) -> Arc<SourceFile>
Returns a ref-counted handle to the underlying SourceFile
Sourcepub fn uri(&self) -> &Uri
pub fn uri(&self) -> &Uri
Returns the URI of the file this SourceFileRef is selecting
Sourcepub const fn span(&self) -> SourceSpan
pub const fn span(&self) -> SourceSpan
Returns the SourceSpan selected by this SourceFileRef
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the underlying str
selected by this SourceFileRef
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the underlying bytes selected by this SourceFileRef
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of bytes represented by the subset of the underlying file that is covered by this SourceFileRef
Trait Implementations§
Source§impl AsRef<[u8]> for SourceFileRef
impl AsRef<[u8]> for SourceFileRef
Source§impl AsRef<str> for SourceFileRef
impl AsRef<str> for SourceFileRef
Source§impl Clone for SourceFileRef
impl Clone for SourceFileRef
Source§fn clone(&self) -> SourceFileRef
fn clone(&self) -> SourceFileRef
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SourceFileRef
impl Debug for SourceFileRef
Source§impl From<&SourceFileRef> for SourceSpan
impl From<&SourceFileRef> for SourceSpan
Source§fn from(source: &SourceFileRef) -> Self
fn from(source: &SourceFileRef) -> Self
Source§impl Hash for SourceFileRef
impl Hash for SourceFileRef
Source§impl Ord for SourceFileRef
impl Ord for SourceFileRef
Source§impl PartialEq for SourceFileRef
impl PartialEq for SourceFileRef
Source§impl PartialOrd for SourceFileRef
impl PartialOrd for SourceFileRef
Source§impl SourceCode for SourceFileRef
impl SourceCode for SourceFileRef
Source§fn read_span<'a>(
&'a self,
span: &SourceSpan,
context_lines_before: usize,
context_lines_after: usize,
) -> Result<Box<dyn SpanContents<'a> + 'a>, MietteError>
fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<Box<dyn SpanContents<'a> + 'a>, MietteError>
SourceCode
, keeping a
certain number of lines before and after the span as context.