Skip to main content

VirtualFilesystem

Struct VirtualFilesystem 

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

An in-memory virtual filesystem for use in tests and sandboxed execution.

Implementations§

Source§

impl VirtualFilesystem

Source

pub fn new() -> Self

Create an empty virtual filesystem.

Source

pub fn set_read_only(&mut self, ro: bool)

Mark the filesystem as read-only.

Source

pub fn mkdir(&mut self, path: &str) -> bool

Create a directory.

Source

pub fn write_file(&mut self, path: &str, contents: &[u8]) -> Result<(), IoError>

Write a file.

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>, IoError>

Read a file.

Source

pub fn delete_file(&mut self, path: &str) -> bool

Delete a file.

Source

pub fn file_exists(&self, path: &str) -> bool

Check whether a file exists.

Source

pub fn dir_exists(&self, path: &str) -> bool

Check whether a directory exists.

Source

pub fn list_dir(&self, dir: &str) -> Vec<String>

List files in a directory (shallow).

Source

pub fn file_size(&self, path: &str) -> Option<usize>

File size.

Source

pub fn append_file( &mut self, path: &str, contents: &[u8], ) -> Result<(), IoError>

Append to a file (creating it if it doesn’t exist).

Source

pub fn copy_file(&mut self, src: &str, dst: &str) -> Result<(), IoError>

Copy a file.

Source

pub fn rename_file(&mut self, src: &str, dst: &str) -> Result<(), IoError>

Rename a file.

Source

pub fn file_count(&self) -> usize

Total number of files.

Source

pub fn total_bytes(&self) -> usize

Total bytes stored.

Trait Implementations§

Source§

impl Default for VirtualFilesystem

Source§

fn default() -> Self

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

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<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, 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.