[][src]Macro resource::resource_str

macro_rules! resource_str {
    ([ $($filenames:tt),* $(,)* ], $load_fn:expr) => { ... };
    (( $($filenames:tt),* $(,)* ), $load_fn:expr) => { ... };
    ([ $($filenames:tt),* $(,)* ]) => { ... };
    (( $($filenames:tt),* $(,)* )) => { ... };
    ($filename:tt, $load_fn:expr) => { ... };
    ($filename:tt) => { ... };
}

Load text 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 text file:

use resource::resource_str;

let toml = resource_str!("Cargo.toml");
assert!(toml.contains("[package]"));

Load an array or tuple of text files:

use resource::resource_str;

let (toml, lib) = resource_str!(("Cargo.toml", "src/lib.rs"));
let as_array = resource_str!(["Cargo.toml", "src/lib.rs"]);

assert_eq!(toml.as_ref(), as_array[0].as_ref());
assert_eq!(lib.as_ref(), as_array[1].as_ref());

Load multiple text files and apply a transformation to each one:

use resource::resource_str;

let [toml, lib] = resource_str!(["Cargo.toml", "src/lib.rs"], str::to_uppercase);

assert!(toml.contains("RESOURCE"));
assert!(lib.contains("MACRO_RULES"));