pub struct SourceFile { /* private fields */ }Expand description
A SourceFile represents a single file stored in a super::SourceManager
Implementations§
Source§impl SourceFile
impl SourceFile
Sourcepub fn new(
id: SourceId,
path: impl Into<Arc<str>>,
content: impl Into<Box<str>>,
) -> Self
pub fn new( id: SourceId, path: impl Into<Arc<str>>, content: impl Into<Box<str>>, ) -> Self
Create a new SourceFile from its raw components
Sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Get the path of this source file as a std::path::Path
Sourcepub fn content(&self) -> &SourceContent
pub fn content(&self) -> &SourceContent
Returns a reference to the underlying SourceContent
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Returns the number of lines in this file
Sourcepub fn source_span(&self) -> SourceSpan
pub fn source_span(&self) -> SourceSpan
Returns a SourceSpan covering the entirety of this file
Sourcepub fn source_slice(&self, span: impl Into<Range<usize>>) -> Option<&str>
pub fn source_slice(&self, span: impl Into<Range<usize>>) -> Option<&str>
Returns a subset of the underlying content as a string slice.
The bounds of the given span are character indices, not byte indices.
Returns None if the given span is out of bounds
Sourcepub fn slice(self: &Arc<Self>, span: impl Into<Range<u32>>) -> SourceFileRef
pub fn slice(self: &Arc<Self>, span: impl Into<Range<u32>>) -> SourceFileRef
Returns a SourceFileRef corresponding to the bytes contained in the specified span.
Sourcepub fn line_column_to_span(&self, line: u32, column: u32) -> Option<SourceSpan>
pub fn line_column_to_span(&self, line: u32, column: u32) -> Option<SourceSpan>
Get a SourceSpan which points to the first byte of the character at column on line
Returns None if the given line/column is out of bounds for this file.
Sourcepub fn location(&self, span: SourceSpan) -> FileLineCol
pub fn location(&self, span: SourceSpan) -> FileLineCol
Get a FileLineCol equivalent to the start of the given SourceSpan
Trait Implementations§
Source§impl AsRef<[u8]> for SourceFile
impl AsRef<[u8]> for SourceFile
Source§impl AsRef<Path> for SourceFile
impl AsRef<Path> for SourceFile
Source§impl AsRef<str> for SourceFile
impl AsRef<str> for SourceFile
Source§impl Clone for SourceFile
impl Clone for SourceFile
Source§fn clone(&self) -> SourceFile
fn clone(&self) -> SourceFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more