web-static-pack
web-static-pack is the "loader" (2nd stage) part of the web-static-pack project. See project page for a general idea how two parts cooperate.
Once a pack
is created with build script / CI / build.rs using
web-static-pack-packer
it will usually be included in your target application with
https://docs.rs/include_bytes_aligned/latest/include_bytes_aligned/.
Then it will be loaded with a [loader::load], utilizing zero-copy
deserialization (so file contents will be sent from executable contents
directly). The pack is then possibly wrapped with [responder::Responder]
http service and used with a web server like hyper.
The main part of this crate is [responder::Responder]. Its [responder::Responder::respond_flatten] method makes a [http] service - a function taking [http::Request] parts (method, path, headers) and returning [http::Response].
To make a [responder::Responder], a [common::pack::Pack] is needed. It can
be obtained by [loader::load] function by passing (possibly included in
binary) contents of a pack
created with the packer.
Examples
Creating and calling responder
use Error;
use include_bytes_aligned;
use ;
use ;
// assume we have a vcard-personal-portfolio.pack available from packer examples
static PACK_ARCHIVED_SERIALIZED: & =
include_bytes_aligned!;
Adapting to hyper service
This example is based on https://hyper.rs/guides/1/server/graceful-shutdown/ which is a bit complicated.
You can run full working example from
tests/examples/vcard_personal_portfolio_server.rs
use Error;
use Responder;
use ;
async
License: MIT