#http #rocket #static #web #server

rust-embed

Rust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev

15 releases (3 major breaking)

3.0.1 Jul 24, 2018
2.0.0 May 26, 2018
1.1.1 Mar 18, 2018
0.5.2 Mar 16, 2018
0.2.0 Mar 16, 2017

#21 in HTTP server

Download history 20/week @ 2018-05-05 4/week @ 2018-05-12 6/week @ 2018-05-19 51/week @ 2018-05-26 79/week @ 2018-06-02 30/week @ 2018-06-09 144/week @ 2018-06-16 37/week @ 2018-06-23 206/week @ 2018-06-30 100/week @ 2018-07-07 110/week @ 2018-07-14 75/week @ 2018-07-21 73/week @ 2018-07-28

296 downloads per month

Rust Embed Build Status crates.io

Rust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.

You can use this to embed your css, js and images into a single executable which can be deployed to your servers. Also it makes it easy to build a very small docker image for you to deploy.

Dev

Release

Installation

[dependencies]
rust-embed="3.0.0"

Documentation

Declare a struct name it Asset or something and add an attribute folder to it which has the path to your static folder.

#[derive(RustEmbed)]
#[folder = "examples/public/"]
struct Asset;

Usage

#[macro_use]
extern crate rust_embed;

#[derive(RustEmbed)]
#[folder = "examples/public/"]
struct Asset;

fn main() {
  let index_html = Asset::get("index.html").unwrap();
  println!("{:?}", std::str::from_utf8(&index_html));
}

Examples

To run the example in dev mode where it reads from the fs,

cargo run --example basic

To run the example in release mode where it reads from binary,

cargo run --example basic --release

Note: To run the actix-web example:

cargo run --example actix --features actix

Note: To run the rocket example, add the nightly feature flag and run on a nightly build:

cargo +nightly run --example rocket --features nightly

Testing

debug: cargo test --test lib

release: cargo test --test lib --release

Go Rusketeers! The power is yours!

MIT license

Dependencies

Reverse deps