rbfs

Crates.iorbfs
lib.rsrbfs
version0.1.7
sourcesrc
created_at2022-12-06 04:25:18.972237
updated_at2022-12-07 08:25:06.859074
descriptionDead simple in-memory filesystem for packaging assets.
homepagehttps://github.com/IsaccBarker/rbfs
repositoryhttps://github.com/IsaccBarker/rbfs
max_upload_size
id730848
size42,980
Milo Banks (IsaccBarker)

documentation

README

Rust Build-time File System

Crates.io Docs.rs

RBFS is a dead simple interface for creating a virtual filesystem in memory. Once populated, probably in your build.rs, RBFS generates Rust source code which is linked into your main Rust program. During runtime, you can access any files you shoved into your RBFS code.

----------------                    --------------------
|   build.rs   | --- generates ---> |   resources.rs   |
----------------                    --------------------

Figure 1: Program can now access the files packed into RBFS in the build script by including the
resources.rs file.

It's very useful in, for example, games, where you might want to package image data, configuration files, audio, etc...

Usage

Include it in your Cargo.toml manifest. The following is a basic example.

// Create the filesystem.
let fs = FileSystem::new();

// Create a path to a virtual location in the filesystem, representing images..
let mut image_directory = fs.get_base_path();
image_directory.push("assets");
image_directory.push("imgs");

// Refering to an icon.png, which will be included via include_bytes! at preprocess time.
// If you want the file to be loaded as a string, change the true to a false to denote
// it's existing as being a binary file.
let icon = fs.add_file(PathBuf::from("icon.png"), &image_directory, false, true);

// If you want to make RBFS output a different filename than supplied, do the following:
let config = fs.add_file(PathBuf::from("matt.conf"), &PathBuf::from("movie.conf"), true, true);

// Generate the Rust code.
let code = fs.code();

let resources_rs = File::create(concat!(env!("CARGO_MANIFEST_DIR"), "/src/resources.rs")).unwrap();
writeln!(resources_rs, "{}", code).unwrap();

Authors

Made with 🫀 by Milo Banks.

Commit count: 13

cargo fmt