This is a crate which provides macros static_resources_initialize!
and static_response!
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 rocketincludestatic_resources::{EtagIfNoneMatch, StaticResponse};
fn favicon(etagifnonematch: EtagIfNoneMatch) -> StaticResponse { staticresponse!(etagifnone_match, "favicon") }
fn faviconpng() -> StaticResponse { staticresponse!("favicon-png") }
fn index(etagifnonematch: EtagIfNoneMatch) -> StaticResponse { staticresponse!(etagifnone_match, "html-readme") }
fn main() { rocket::ignite() .attach(StaticResponse::fairing(|resources| { staticresourcesinitialize!( resources,
"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])
.launch();
} ```
static_resources_initialize!
is used in the fairing of StaticResponse
to include static files into your executable binary file. You need to specify each file's name and its path. 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!
is used for retrieving the file you input through the macro static_resources_initialize!
as a Response instance into which three HTTP headers, Content-Type, Content-Length and Etag, will be automatically added.See examples
.
https://crates.io/crates/rocket-include-static-resources
https://docs.rs/rocket-include-static-resources