Crate vfs

source ·
Expand description

Virtual file system abstraction

The virtual file system abstraction generalizes over file systems and allow using different VirtualFileSystem implementations (i.e. an in memory implementation for unit tests)

The main interaction with the virtual filesystem is by using virtual paths (VfsPath).

This crate currently has the following implementations:

  • PhysicalFS - the actual filesystem of the underlying OS
  • MemoryFS - an ephemeral in-memory implementation (intended for unit tests)
  • AltrootFS - a file system with its root in a particular directory of another filesystem
  • OverlayFS - a union file system consisting of a read/writable upper layer and several read-only lower layers
  • EmbeddedFS - a read-only file system embedded in the executable, requires embedded-fs feature

Usage Examples

use vfs::{VfsPath, PhysicalFS, VfsError};

let root: VfsPath = PhysicalFS::new(std::env::current_dir().unwrap()).into();

let mut content = String::new();
root.join("")?.open_file()?.read_to_string(&mut content)?;
use vfs::{VfsPath, VfsError, MemoryFS};

let root: VfsPath = MemoryFS::new().into();
let path = root.join("test.txt")?;

path.create_file()?.write_all(b"Hello world")?;
let mut content = String::new();
path.open_file()?.read_to_string(&mut content)?;
assert_eq!(content, "Hello world");


pub use error::VfsError;
pub use error::VfsResult;
pub use filesystem::FileSystem;
pub use impls::altroot::AltrootFS;
pub use impls::embedded::EmbeddedFS;
pub use impls::memory::MemoryFS;
pub use impls::overlay::OverlayFS;
pub use impls::physical::PhysicalFS;
pub use path::*;


Error and Result definitions
The filesystem trait definitions needed to implement new virtual filesystems
Virtual filesystem implementations
Virtual filesystem path