Generates rust code to embed resource files into your rust executable
```bash ./rust-embed
rust-embed v0.1.0 Generates rust code to embed resource files/folders at compile time into your library or executable
Usage: rust-embed inputfolder outputfile
where: inputfolder string is the path to the folder containing the assets. outputfile string is output filename.
example: rust-embed src/public src/assets.rs ```
You can use this to embed your css, js and images into a single executable.
This is similar to go-bindata.
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 whereas rust-embed generates code when the command is run. And rust-embed works only on folders.
cargo install rust-embed
It exposes a function to serve all files stored in your assets folder which is useful for webservers. So now you can statically compile all your assets i.e. your /static/ or /public/ folders into the rust executable and serve them. So now you don't need to package your assets with your executable.
```rust assets::get(path: str) -> Result<&[u8], &str> // This will return the data for the file specified by the file path or an error if it cannot be found.
assets::list() -> Vec<&'static str> // This will return the list of all files which were included ```
A simple http server which serves its resources directly.
To compile the assets for the examples,
rust-embed examples/public/ examples/assets.rs
To run the examples,
cargo run --example http
```rust extern crate hyper; use hyper::Server; use hyper::server::Request; use hyper::server::Response; use hyper::net::Fresh;
mod assets;
fn handleindex(: Request, res: Response
fn main() { println!("Server running on 127.0.0.1:3000"); Server::http("127.0.0.1:3000").unwrap().handle(handle_index).unwrap(); } ```
Go Rusketeers! The power is yours!
rewrite this to use compiler plugins and macro so that we can use that instead