Rust Embed
Rust Marco 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.
This is similar to go-embed.
This is similar to pony-embed.
Note:
This is not the same as std macros,
include_bytes!
include_str!
these are macros which generate code at compile time for only files.
embed!("examples/public/")
accepts folders and returns a function to get the contents using the file path
Installation
[dependencies]
rust-embed="0.5.2"
Documentation
The embed!
macro takes a folder path and returns a function which allows you to get the file by passing the file path within the folder. So now you can statically compile all your assets i.e. your /static/ or /public/ folders into the rust executable and serve them during release and in development it will load the file from the file
system so that it doesn't take to much time to compile;]
asset
Usage
extern crate rust_embed;
use *;
Examples
To run the example in dev mode where it reads from the fs,
cargo run --example rocket
To run the example in release mode where it reads from binary,
cargo run --release --example rocket
Testing
debug: cargo test --lib
release: cargo test --lib --release
Go Rusketeers! The power is yours!