Skip to main content

MemoryFs

Struct MemoryFs 

Source
pub struct MemoryFs { /* private fields */ }
Expand description

A Fs backed by a map of path to file contents.

See the module documentation for the constraints that come with it: reads are synchronous, so every file must be inserted before the compile begins.

Cloning copies every stored file, so prefer to build one and pass it by reference.

Implementations§

Source§

impl MemoryFs

Source

pub fn new() -> MemoryFs

Creates a filesystem with no files in it.

Compiling against it behaves like NullFs: every import fails to resolve.

Source

pub fn insert<P, C>(&mut self, path: P, contents: C)
where P: AsRef<Path>, C: Into<Vec<u8>>,

Adds a file, replacing whatever was at that path.

The path is normalized, so ./a.scss and a.scss are the same entry. Every ancestor directory of the path starts reporting true from Fs::is_dir.

The contents may be any bytes, but the compiler rejects a file that is not valid UTF-8 when it reads it, not when you insert it.

Source

pub fn len(&self) -> usize

Returns the number of files stored.

Source

pub fn is_empty(&self) -> bool

Returns true when no files are stored.

Source

pub fn loaded_paths(&self) -> Vec<PathBuf>

Returns the paths that have been read, in the order they were read.

A path appears once per read, so a stylesheet the compiler consults twice appears twice. Use it to report which files a compile depended on – to invalidate a cache, or to show a user what a framework actually pulled in.

Source

pub fn clear_loaded_paths(&self)

Forgets the record of which paths have been read.

Call it between compiles when you reuse one filesystem, so that loaded_paths describes the latest compile rather than every compile so far.

Trait Implementations§

Source§

impl Clone for MemoryFs

Source§

fn clone(&self) -> MemoryFs

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryFs

Prints the file count rather than the files.

Fs requires Debug, and a derived one would dump every stylesheet in the tree – megabytes, for a framework – into any log line that formats the options.

Source§

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

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

impl Default for MemoryFs

Source§

fn default() -> MemoryFs

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

impl Fs for MemoryFs

Source§

fn read(&self, path: &Path) -> Result<Vec<u8>, Error>

Reads a stored file.

§Errors

Returns ErrorKind::NotFound when no file is stored at the path. The compiler turns that into Can't find stylesheet to import. at the @use or @import that asked for it.

Source§

fn canonicalize(&self, path: &Path) -> Result<PathBuf, Error>

Normalizes the path.

The compiler uses the result as the identity of a loaded module, so this must map every spelling of one file onto a single path. It never fails: an unknown path normalizes like any other, and the read that follows is what reports that the file is missing.

Source§

fn is_dir(&self, path: &Path) -> bool

Returns true if the path exists on disk and is pointing at a directory.
Source§

fn is_file(&self, path: &Path) -> bool

Returns true if the path exists on disk and is pointing at a regular file.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.