The macro can be used like this:
flate!($meta $vis static $name: $type from $file);
$metais zero or more
#[...]attributes that can be applied on the static parameters of
lazy_static. For the actual semantics of the meta attributes, please refer to
$visis a visibility modifier (e.g.
pub(crate)) or empty.
$nameis the name of the static variable..
$typecan be either
str. However, the actual type created would dereference into
String(although they are
$fileis either an absolute path or a path relative to the current
CARGO_MANIFEST_DIR. Note that this is distinct from the behaviour of the builtin
include_str!paths are relative to the current source file, while
flate!paths are relative to
The macro expands to a
lazy_static call, which lazily inflates the compressed bytes.
- If the input format is incorrect
- If the referenced file does not exist or is not readable
strbut the file is not fully valid UTF-8
Compression and decompression use the DEFLATE algorithm from
Below are some basic examples. For actual compiled examples, see the
// This declares a `static VAR_NAME: impl Deref<Vec<u8>>` flate!(static VAR_NAME: [u8] from "binary-file.dat"); // This declares a `static VAR_NAME: impl Deref<String>` flate!(static VAR_NAME: str from "text-file.txt"); // Visibility modifiers can be added in the front flate!(pub static VAR_NAME: str from "public-file.txt"); // Meta attributes can also be added flate!(#[allow(unused)] #[doc = "Example const"] pub static VAR_NAME: str from "file.txt");