pub struct InMemoryFileSystem { /* private fields */ }
Expand description

In-memory filesystem for use in unit tests.

This type mocks out the file system operations in the VM. It provides an in-memory system to which “files” can be added before the test runs. It is designed to help test primitives that interact with the filesystem.

Given a VM, the file system can be set as follows:

#[derive(Default)]
struct State {
    file_system: Rc<RefCell<InMemoryFileSystem>>,
}
let mut vm = vm::VM::<State>::new_with_built_in_commands(
    HashMap::new(),  // empty set of built-in commands
);
let mut mock_file_system = InMemoryFileSystem::new(&vm.working_directory.as_ref().unwrap());
mock_file_system.add("file/path.tex", "file content");
vm.state.file_system = Rc::new(RefCell::new(mock_file_system));

Implementations§

source§

impl InMemoryFileSystem

source

pub fn new(working_directory: &Path) -> Self

Create a new in-memory file system.

Typically the working directory is taken from the VM.

source

pub fn add(&mut self, relative_path: &str, content: &str)

Add a file to the in-memory file system.

The provided path is relative to the working directory

Trait Implementations§

source§

impl Default for InMemoryFileSystem

source§

fn default() -> InMemoryFileSystem

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

impl FileSystem for InMemoryFileSystem

source§

fn read_to_string(&self, path: &Path) -> Result<String>

Read the entire contents of a file into a string. Read more
source§

fn write_bytes(&self, _: &Path, _: &[u8]) -> Result<()>

Write a slice of bytes to a file. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.