Skip to main content

MemoryFs

Struct MemoryFs 

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

MemoryFs is a simple in-memory filesystem that can be used for testing purposes.

It implements the RemoteFs trait.

The MemoryFs is instantiated providing a orange_trees::Tree which contains the filesystem data.

When reading or writing files, the MemoryFs will use the orange_trees::Tree to store the data.

You can easily create the MemoryFs using the MemoryFs::new method, providing the tree. Use the node! macro to create the tree or use the orange_trees crate to create it programmatically.

The tree contains nodes identified by a PathBuf and a value of type Inode. Every path passed to the client must be absolute; the tree root is /.

Implementations§

Source§

impl MemoryFs

Source

pub fn new(tree: FsTree) -> Self

Create a client backed by tree.

uid/gid default to 0 for every file until MemoryFs::with_get_uid or MemoryFs::with_get_gid is used to override them.

§Examples
use std::path::PathBuf;

use remotefs::fs::UnixPex;
use remotefs_memory::{Inode, MemoryFs, Node, Tree, node};

let tree = Tree::new(node!(
    PathBuf::from("/"),
    Inode::dir(0, 0, UnixPex::from(0o755))
));
let client = MemoryFs::new(tree);
Source

pub fn with_get_uid<F>(self, get_uid: F) -> Self
where F: Fn() -> u32 + Send + Sync + 'static,

Override the closure used to fill the uid of newly created files.

§Examples
use std::path::PathBuf;

use remotefs::fs::UnixPex;
use remotefs_memory::{Inode, MemoryFs, Node, Tree, node};

let tree = Tree::new(node!(
    PathBuf::from("/"),
    Inode::dir(0, 0, UnixPex::from(0o755))
));
let client = MemoryFs::new(tree).with_get_uid(|| 1000);
Source

pub fn with_get_gid<F>(self, get_gid: F) -> Self
where F: Fn() -> u32 + Send + Sync + 'static,

Override the closure used to fill the gid of newly created files.

§Examples
use std::path::PathBuf;

use remotefs::fs::UnixPex;
use remotefs_memory::{Inode, MemoryFs, Node, Tree, node};

let tree = Tree::new(node!(
    PathBuf::from("/"),
    Inode::dir(0, 0, UnixPex::from(0o755))
));
let client = MemoryFs::new(tree).with_get_gid(|| 1000);

Trait Implementations§

Source§

impl RemoteFs for MemoryFs

Source§

fn connect(&mut self) -> RemoteResult<()>

Connects to the remote server and authenticates the client. Read more
Source§

fn disconnect(&mut self) -> RemoteResult<()>

Disconnects from the remote server. Read more
Source§

fn is_connected(&self) -> bool

Returns the cached connection state without probing the transport.
Source§

fn capabilities(&self) -> Capabilities

Returns the operations natively supported by this client.
Source§

fn list_dir(&self, path: &Path) -> RemoteResult<Vec<File>>

Lists the direct children of an absolute directory path. Read more
Source§

fn stat(&self, path: &Path) -> RemoteResult<File>

Returns metadata for an absolute path without following symlinks. Read more
Source§

fn exists(&self, path: &Path) -> RemoteResult<bool>

Reports whether an absolute path exists. Read more
Source§

fn set_metadata(&self, path: &Path, metadata: &SetMetadata) -> RemoteResult<()>

Changes the specified metadata fields of an absolute path. Read more
Source§

fn create_dir(&self, path: &Path, mode: Option<UnixPex>) -> RemoteResult<()>

Creates a directory at an absolute path. Read more
Source§

fn remove_file(&self, path: &Path) -> RemoteResult<()>

Removes a file or symbolic link at an absolute path.
Source§

fn remove_dir(&self, path: &Path) -> RemoteResult<()>

Removes an empty directory at an absolute path.
Source§

fn remove_dir_all(&self, path: &Path) -> RemoteResult<()>

Removes an entry and its descendants using depth-first traversal. Read more
Source§

fn rename(&self, src: &Path, dest: &Path) -> RemoteResult<()>

Renames an absolute source path to an absolute destination path.
Source§

fn copy(&self, src: &Path, dest: &Path) -> RemoteResult<()>

Copies an absolute source path to an absolute destination path.
Creates a symbolic link at path pointing to an absolute target.
Source§

fn open(&self, path: &Path, opts: &ReadOptions) -> RemoteResult<ReadStream>

Opens an absolute file path for a ranged read.
Source§

fn create(&self, path: &Path, opts: &WriteOptions) -> RemoteResult<WriteStream>

Creates or truncates an absolute file path for writing.
Source§

fn append(&self, path: &Path, opts: &WriteOptions) -> RemoteResult<WriteStream>

Opens or creates an absolute file path for appending.
Source§

fn exec(&self, _cmd: &str) -> RemoteResult<ExecOutput>

Executes a command and returns its exit code and standard output.
Source§

fn read_file( &self, path: &Path, opts: &ReadOptions, dest: &mut (dyn Write + Send), ) -> Result<u64, RemoteError>

Reads a remote file into a borrowed destination and finalizes its stream. Read more
Source§

fn write_file( &self, path: &Path, opts: &WriteOptions, src: &mut (dyn Read + Send), ) -> Result<u64, RemoteError>

Writes a borrowed source to a remote file and finalizes its stream. Read more
Source§

fn append_file( &self, path: &Path, opts: &WriteOptions, src: &mut (dyn Read + Send), ) -> Result<u64, RemoteError>

Appends a borrowed source to a remote file and finalizes its stream.

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 = !

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.