pub struct Sources { /* private fields */ }
Expand description
A collection of source files.
Implementations§
Source§impl Sources
impl Sources
Sourcepub fn get(&self, id: SourceId) -> Option<&Source>
pub fn get(&self, id: SourceId) -> Option<&Source>
Get the source matching the given source id.
§Examples
use rune::{Sources, Source};
let mut sources = Sources::new();
let id = sources.insert(Source::new("<memory>", "pub fn main() { 10 }")?)?;
let source = sources.get(id).context("expected source")?;
assert_eq!(source.name(), "<memory>");
Trait Implementations§
Source§impl<'a> Files<'a> for Sources
impl<'a> Files<'a> for Sources
Source§type FileId = SourceId
type FileId = SourceId
A unique identifier for files in the file provider. This will be used
for rendering
diagnostic::Label
s in the corresponding source files.Source§fn name(&'a self, file_id: SourceId) -> Result<Self::Name, Error>
fn name(&'a self, file_id: SourceId) -> Result<Self::Name, Error>
The user-facing name of a file.
Source§fn source(&'a self, file_id: SourceId) -> Result<Self::Source, Error>
fn source(&'a self, file_id: SourceId) -> Result<Self::Source, Error>
The source code of a file.
Source§fn line_index(
&self,
file_id: SourceId,
byte_index: usize,
) -> Result<usize, Error>
fn line_index( &self, file_id: SourceId, byte_index: usize, ) -> Result<usize, Error>
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: SourceId,
line_index: usize,
) -> Result<Range<usize>, Error>
fn line_range( &self, file_id: SourceId, line_index: usize, ) -> Result<Range<usize>, Error>
The byte range of line in the source of the file.
Source§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 Sources
impl RefUnwindSafe for Sources
impl Send for Sources
impl Sync for Sources
impl Unpin for Sources
impl UnwindSafe for Sources
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