Macro resource::resource [−][src]
macro_rules! resource { ([ $($filenames:tt),* $(,)* ], $load_fn:expr) => { ... }; (( $($filenames:tt),* $(,)* ), $load_fn:expr) => { ... }; ([ $($filenames:tt),* $(,)* ]) => { ... }; (( $($filenames:tt),* $(,)* )) => { ... }; ($filename:tt, $load_fn:expr) => { ... }; ($filename:tt) => { ... }; }
Load binary resources statically in release mode, or dynamically in debug.
The filenames are relative to the root of your crate.
If you wish to override the static or dynamic behaviour, you can use the
force-static
or force-dynamic
features.
This macro optionally takes a function which can be used to transform the contents of each file on load.
Panics
When dynamically including, this will panic if any file does not exist. When statically including, this will be a compile error and will never panic.
Examples
Load a single binary file:
let toml = resource!("Cargo.toml"); assert_eq!(&toml[0..9], b"[package]");
Load an array or tuple of binary files:
let (toml, lib) = resource!(("Cargo.toml", "src/lib.rs")); let as_array = resource!(["Cargo.toml", "src/lib.rs"]); assert_eq!(toml, as_array[0]); assert_eq!(lib, as_array[1]);
Load binary files and apply a transformation to each one:
let [toml, lib] = resource!(["Cargo.toml", "src/lib.rs"], |bytes: &[u8]| bytes.to_ascii_uppercase()); assert_eq!(&toml[0..9], b"[PACKAGE]"); assert_eq!(&lib[0..4], b"//! ");