Skip to main content

static_compiled

Macro static_compiled 

Source
macro_rules! static_compiled {
    ($($args:tt)*) => { ... };
}
Expand description

The preferred interface to build a StaticCompiledHandler.

static_compiled!("assets") is identical to StaticCompiledHandler::new(root!("assets")).

§Arguments

The first argument is a string literal naming a path on disk. After the path, any number of optional arguments may follow in any order, separated by commas:

static_compiled!("./public");                                // defaults
static_compiled!("./public", etag = false);                  // skip etag
static_compiled!("./public", compress);                      // all enabled encoders
static_compiled!("./public", compress = [Brotli, Gzip]);     // specific encoders
static_compiled!("./public", compress, etag = false);        // both

§etag = bool

On by default. When true, an entity tag is computed at compile time for each file’s source bytes and emitted as the ETag response header. See the crate-level docs for details.

§compress and compress = [Brotli, Zstd, Gzip]

Off by default and gated behind the brotli / zstd / gzip / compression cargo features. The bare form compress bakes every encoding whose feature is enabled; the listed form bakes a specified subset and is a compile error if a listed encoding’s feature is not enabled. See the crate-level docs.

§Relative paths

Relative paths are expanded and canonicalized relative to $CARGO_MANIFEST_DIR, which is usually the directory that contains your Cargo.toml. If compiled within a workspace, this will be the subcrate’s Cargo.toml.

§Environment variable expansion

If the path argument to static_compiled! contains substrings that are formatted like an environment variable, beginning with a $, they will be interpreted in the compile time environment.

For example "$OUT_DIR/some_directory" will expand to the directory some_directory within the env variable $OUT_DIR set by cargo. See this link for further documentation on the environment variables set by cargo.