web-static-pack

Embed static resources (GUI, assets, images, styles, html) within executable. Serve with hyper or any server of your choice.

docs.rs

Usage scenario:

Features:

Limitations:

Future goals:

Non-Goals:

Example:

  1. Create a pack from cargo doc: $ cargo doc --no-deps $ cargo run --example packer ./target/doc/ docs.pack

  2. Serve docs.pack from your web-application (see examples/docs) ``` use failure::Error; use hyper::service::{makeservicefn, servicefn}; use hyper::{Body, Request, Response, Server}; use lazystatic::lazystatic; use std::convert::Infallible; use std::net::SocketAddr; use webstaticpack::hyperloader::{Responder, StaticBody}; use webstaticpack::loader::Loader;

[tokio::main]

async fn main() -> () { simplelogger::initwithlevel(log::Level::Info).unwrap(); mainresult().await.unwrap() }

async fn service(request: Request) -> Result, Infallible> { lazystatic! { static ref PACK: &'static [u8] = std::includebytes!("docs.pack"); static ref LOADER: Loader = Loader::new(&PACK).unwrap(); static ref RESPONDER: Responder<'static> = Responder::new(&LOADER); }

Ok(RESPONDER.respond(&request))

}

async fn mainresult() -> Result<(), Error> { let address = SocketAddr::from(([0, 0, 0, 0], 8080)); let server = Server::bind(&address).serve(makeservicefn(|connection| async { Ok::<_, Infallible>(service_fn(service)) }));

log::info!("Server listening on {:?}", address);
Ok(server.await?)

} ```