This is a crate which provides macros static_resources_initializer!
and static_response_handler!
to statically include files from your Rust project and make them be the HTTP response sources quickly.
```rust
extern crate rocket;
extern crate rocketincludestatic_resources;
use rocket::State;
use rocketincludestatic_resources::{EtagIfNoneMatch, StaticContextManager, StaticResponse};
staticresponsehandler! { "/favicon.ico" => favicon => "favicon", "/favicon-16.png" => favicon_png => "favicon-png", }
fn index(
staticresources: &State
fn rocket() -> _ { rocket::build() .attach(staticresourcesinitializer!( "favicon" => "examples/front-end/images/favicon.ico", "favicon-png" => "examples/front-end/images/favicon-16.png", "html-readme" => ("examples", "front-end", "html", "README.html"), )) .mount("/", routes![favicon, favicon_png]) .mount("/", routes![index]) } ```
static_resources_initializer!
is used for including files into your executable binary file. You need to specify each file's name and its path relative to the directory containing the manifest of your package. For instance, the above example uses favicon to represent the file included-static-resources/favicon.ico and favicon_png to represent the file included-static-resources/favicon.png. A name cannot be repeating. In order to reduce the compilation time and allow to hot-reload resources, files are compiled into your executable binary file together, only when you are using the release profile.static_response_handler!
is used for quickly creating GET route handlers to retrieve static resources.See examples
.
https://crates.io/crates/rocket-include-static-resources
https://docs.rs/rocket-include-static-resources