pub struct SourceFiles { /* private fields */ }Expand description
A file database that can store multiple source files.
This is taking as is from codespan_reporting::files::SimpleFiles with
the added ability to iterate over the files
There are a few TODOs on this structure that may or may not be needed:
- Use a custom
SourceFilestructure instead ofSimpleFile - Use a deterministic
FileIdinstead of usingusize
Implementations§
Source§impl SourceFiles
impl SourceFiles
Sourcepub fn new() -> SourceFiles
pub fn new() -> SourceFiles
Create a new files database.
Sourcepub fn add_file(&mut self, file: SourceFile) -> SourceFileId
pub fn add_file(&mut self, file: SourceFile) -> SourceFileId
Add a file to the database, returning the handle that can be used to refer to it again.
Sourcepub fn get(
&self,
file_id: SourceFileId,
) -> Result<&SimpleFile<String, String>, FilesError>
pub fn get( &self, file_id: SourceFileId, ) -> Result<&SimpleFile<String, String>, FilesError>
Get the file corresponding to the given id.
pub fn iter(&self) -> impl Iterator<Item = (SourceFileId, &SourceFile)> + '_
Trait Implementations§
Source§impl Default for SourceFiles
impl Default for SourceFiles
Source§impl<'a> Files<'a> for SourceFiles
impl<'a> Files<'a> for SourceFiles
Source§type FileId = SourceFileId
type FileId = SourceFileId
A unique identifier for files in the file provider. This will be used
for rendering
diagnostic::Labels in the corresponding source files.Source§fn name(&self, file_id: Self::FileId) -> Result<String, FilesError>
fn name(&self, file_id: Self::FileId) -> Result<String, FilesError>
The user-facing name of a file.
Source§fn source(&self, file_id: Self::FileId) -> Result<&String, FilesError>
fn source(&self, file_id: Self::FileId) -> Result<&String, FilesError>
The source code of a file.
Source§fn line_index(
&self,
file_id: Self::FileId,
byte_index: usize,
) -> Result<usize, FilesError>
fn line_index( &self, file_id: Self::FileId, byte_index: usize, ) -> Result<usize, FilesError>
The index of the line at the given byte index.
If the byte index is past the end of the file, returns the maximum line index in the file.
This means that this function only fails if the file is not present. Read more
Source§fn line_range(
&self,
file_id: Self::FileId,
line_index: usize,
) -> Result<Range<usize>, FilesError>
fn line_range( &self, file_id: Self::FileId, line_index: usize, ) -> Result<Range<usize>, FilesError>
The byte range of line in the source of the file.
§fn line_number(
&'a self,
id: Self::FileId,
line_index: usize,
) -> Result<usize, Error>
fn line_number( &'a self, id: Self::FileId, line_index: usize, ) -> Result<usize, Error>
The user-facing line number at the given line index.
It is not necessarily checked that the specified line index
is actually in the file. Read more
Auto Trait Implementations§
impl Freeze for SourceFiles
impl RefUnwindSafe for SourceFiles
impl Send for SourceFiles
impl Sync for SourceFiles
impl Unpin for SourceFiles
impl UnsafeUnpin for SourceFiles
impl UnwindSafe for SourceFiles
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more