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: bash $ cargo doc --no-deps $ cargo run ./target/doc/ docs.pack

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

[tokio::main]

async fn main() -> () { SimpleLogger::fromenv() .withlevel(LevelFilter::Info) .init() .unwrap(); main_result().await.unwrap() }

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

Ok(RESPONDER.request_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.context("server")?)

} ```