Crates.io | rbfs |
lib.rs | rbfs |
version | 0.1.7 |
source | src |
created_at | 2022-12-06 04:25:18.972237 |
updated_at | 2022-12-07 08:25:06.859074 |
description | Dead simple in-memory filesystem for packaging assets. |
homepage | https://github.com/IsaccBarker/rbfs |
repository | https://github.com/IsaccBarker/rbfs |
max_upload_size | |
id | 730848 |
size | 42,980 |
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...
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();
Made with 🫀 by Milo Banks.