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 path(&self) -> &Path
pub fn path(&self) -> &Path
Returns the name of the file this SourceFileRef is selecting, as a std::path::Path
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the name 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 more