pub struct Files { /* private fields */ }Expand description
A cheaply-clonable, persistent, codespan-compatible collection of files.
Files knows about the nickel standard library, and automatically loads it on creation
(but it doesn’t do parsing, or anything particularly expensive).
Cloning a Files is cheap, and the underlying file data will be shared between clones
until one of them wants to modify a file. In that case, only the modified file(s) will
be duplicated.
Implementations§
Source§impl Files
impl Files
pub fn empty() -> Self
Sourcepub fn new<Name, Contents, I>(stdlib_modules: I) -> Self
pub fn new<Name, Contents, I>(stdlib_modules: I) -> Self
Creates a new Files, initialized with the nickel standard library.
Sourcepub fn is_stdlib(&self, id: FileId) -> bool
pub fn is_stdlib(&self, id: FileId) -> bool
Does this file id point to a standard library file?
Sourcepub fn stdlib_modules(&self) -> impl Iterator<Item = FileId> + use<>
pub fn stdlib_modules(&self) -> impl Iterator<Item = FileId> + use<>
Returns the list of file ids of stdlib modules, in the order they were passed
to Files::new.
Sourcepub fn add(
&mut self,
name: impl Into<OsString>,
source: impl Into<Arc<str>>,
) -> FileId
pub fn add( &mut self, name: impl Into<OsString>, source: impl Into<Arc<str>>, ) -> FileId
Adds a file to this collection, creating and returning a new file id.
The name does not need to be unique, and this method does not affect any other files with the same name.
Sourcepub fn update(&mut self, file_id: FileId, source: impl Into<Arc<str>>)
pub fn update(&mut self, file_id: FileId, source: impl Into<Arc<str>>)
Updates a source file in place.
Panics if file_id is invalid.
Sourcepub fn source_span(&self, file_id: FileId) -> RawSpan
pub fn source_span(&self, file_id: FileId) -> RawSpan
Returns a span containing all of a source.
Panics if file_id is invalid.
Sourcepub fn name(&self, id: FileId) -> &OsStr
pub fn name(&self, id: FileId) -> &OsStr
Returns the source’s name.
Panics if file_id is invalid.
Sourcepub fn clone_source(&self, id: FileId) -> Arc<str>
pub fn clone_source(&self, id: FileId) -> Arc<str>
Returns a cloned reference to the source’s contents
Sourcepub fn source_slice(&self, span: RawSpan) -> &str
pub fn source_slice(&self, span: RawSpan) -> &str
Returns a slice of the source’s contents.
Sourcepub fn location(
&self,
id: FileId,
byte_index: impl Into<ByteIndex>,
) -> Result<Location, Error>
pub fn location( &self, id: FileId, byte_index: impl Into<ByteIndex>, ) -> Result<Location, Error>
Returns the codespan::Location (basically: line + col) corresponding
to a byte index.
Returns an error if the byte index is out of bounds or fails to point to a UTF-8 char boundary.
pub fn filenames(&self) -> impl Iterator<Item = &OsStr>
Trait Implementations§
Source§impl<'a> Files<'a> for Files
impl<'a> Files<'a> for Files
Source§type FileId = FileId
type FileId = FileId
diagnostic::Labels in the corresponding source files.Source§fn source(&'a self, id: Self::FileId) -> Result<Self::Source, Error>
fn source(&'a self, id: Self::FileId) -> Result<Self::Source, Error>
Source§fn line_index(
&'a self,
id: Self::FileId,
byte_index: usize,
) -> Result<usize, Error>
fn line_index( &'a self, id: Self::FileId, byte_index: usize, ) -> Result<usize, Error>
Source§fn line_range(
&'a self,
id: Self::FileId,
line_index: usize,
) -> Result<Range<usize>, Error>
fn line_range( &'a self, id: Self::FileId, line_index: usize, ) -> Result<Range<usize>, Error>
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>
Auto Trait Implementations§
impl Freeze for Files
impl RefUnwindSafe for Files
impl !Send for Files
impl !Sync for Files
impl Unpin for Files
impl UnsafeUnpin for Files
impl UnwindSafe for Files
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more