Skip to main content

Files

Struct Files 

Source
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

Source

pub fn empty() -> Self

Source

pub fn new<Name, Contents, I>(stdlib_modules: I) -> Self
where Name: Into<OsString>, Contents: Into<Arc<str>>, I: IntoIterator<Item = (Name, Contents)>,

Creates a new Files, initialized with the nickel standard library.

Source

pub fn is_stdlib(&self, id: FileId) -> bool

Does this file id point to a standard library file?

Source

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.

Source

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.

Source

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.

Source

pub fn source_span(&self, file_id: FileId) -> RawSpan

Returns a span containing all of a source.

Panics if file_id is invalid.

Source

pub fn name(&self, id: FileId) -> &OsStr

Returns the source’s name.

Panics if file_id is invalid.

Source

pub fn source(&self, id: FileId) -> &str

Returns a source’s contents.

Source

pub fn clone_source(&self, id: FileId) -> Arc<str>

Returns a cloned reference to the source’s contents

Source

pub fn source_slice(&self, span: RawSpan) -> &str

Returns a slice of the source’s contents.

Source

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.

Source

pub fn filenames(&self) -> impl Iterator<Item = &OsStr>

Trait Implementations§

Source§

impl Clone for Files

Source§

fn clone(&self) -> Files

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Files

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Files

Source§

fn default() -> Files

Returns the “default value” for a type. Read more
Source§

impl<'a> Files<'a> for Files

Source§

type FileId = FileId

A unique identifier for files in the file provider. This will be used for rendering diagnostic::Labels in the corresponding source files.
Source§

type Name = String

The user-facing name of a file, to be displayed in diagnostics.
Source§

type Source = &'a str

The source code of a file.
Source§

fn name(&'a self, id: Self::FileId) -> Result<String, Error>

The user-facing name of a file.
Source§

fn source(&'a self, id: Self::FileId) -> Result<Self::Source, Error>

The source code of a file.
Source§

fn line_index( &'a self, id: Self::FileId, 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( &'a self, id: Self::FileId, 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>

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
Source§

fn column_number( &'a self, id: Self::FileId, line_index: usize, byte_index: usize, ) -> Result<usize, Error>

The user-facing column number at the given line index and byte index. Read more
Source§

fn location( &'a self, id: Self::FileId, byte_index: usize, ) -> Result<Location, Error>

Convenience method for returning line and column number at the given byte index in the file.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryConvert<'_, T> for U
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

Source§

fn try_convert( _: &AstAlloc, from: T, ) -> Result<U, <U as TryConvert<'_, T>>::Error>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U