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
impl MemoryFs
Sourcepub fn new() -> MemoryFs
pub fn new() -> MemoryFs
Creates a filesystem with no files in it.
Compiling against it behaves like NullFs: every
import fails to resolve.
Sourcepub fn insert<P, C>(&mut self, path: P, contents: C)
pub fn insert<P, C>(&mut self, path: P, contents: C)
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.
Sourcepub fn loaded_paths(&self) -> Vec<PathBuf>
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.
Sourcepub fn clear_loaded_paths(&self)
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 Debug for MemoryFs
Prints the file count rather than the files.
impl Debug for MemoryFs
Prints the file count rather than the files.
Source§impl Fs for MemoryFs
impl Fs for MemoryFs
Source§fn read(&self, path: &Path) -> Result<Vec<u8>, Error>
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>
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.