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.
```rust // Create the filesystem. let fs = FileSystem::new();
// Create a path to a virtual location in the filesystem, representing images.. let mut imagedirectory = fs.getbasepath(); imagedirectory.push("assets"); image_directory.push("imgs");
// Refering to an icon.png, which will be included via includebytes! 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.addfile(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 resourcesrs = File::create(concat!(env!("CARGOMANIFESTDIR"), "/src/resources.rs")).unwrap(); writeln!(resourcesrs, "{}", code).unwrap(); ```
Made with 🫀 by Milo Banks.