Crate vfs_shadow

Crate vfs_shadow 

Source
Expand description

§vfs-shadow

This crate allows embedding files from a directory into a virtual filesystem (VFS) during compile time. The macro load_into_vfs! takes a path to a directory and a filesystem, then loads the contents of the directory into the provided filesystem.

§Usage

Use the load_into_vfs! macro to load files from a directory into a MemoryFS (or any other filesystem that implements vfs::FileSystem):

use vfs_shadow::load_into_vfs;
use vfs::{MemoryFS, FileSystem};

// Load files into a MemoryFS
let fs = load_into_vfs!("example/vfs", MemoryFS::new()).unwrap();

// Interact with the embedded files
assert!(fs.exists("/data.json").is_ok());

You can also pass a reference to an existing filesystem:

use vfs_shadow::load_into_vfs;
use vfs::{MemoryFS, FileSystem};

let fs = MemoryFS::new();
load_into_vfs!("example/vfs", &fs).unwrap();

// Use the filesystem
assert!(fs.exists("/data.json").is_ok());

In both cases, the directory at example/vfs is included in the final binary, and its contents are copied into the provided filesystem.

§Path Resolution

The path provided to load_into_vfs! is relative to the manifest directory. This can change when [proc_macro::Span::source_file] stabilizes in future.

§Return Value

The macro returns a vfs::VfsResult<()>. If an error occurs while copying files into the filesystem, the operation will fail, and execution will stop.

Macros§

load_into_vfs
Embeds files from a directory into a virtual filesystem at compile time.