#web-apps #assets #web #embed #standalone #http #compile-time

reinda

Easily embed and manage your assets for your web application to build standalone-executables. Offers filename hashing, templating, compression and more.

3 unstable releases

0.2.1 Apr 17, 2023
0.2.0 Jan 27, 2021
0.1.0 Jan 22, 2021

#333 in Caching

33 downloads per month

MIT/Apache

64KB
875 lines

reinda: easily embed and manage assets

CI status of master Crates.io Version docs.rs

This library helps you manage your assets (external files) and is mostly intended to be used in web applications. Assets can be embedded into the binary file to obtain an easy to deploy standalone executable. This crate also offers a template engine and the ability to automatically include a hash of an asset's content into its filename (useful for caching on the web). In release mode, this crate prepares everything up-front such that the actually serving the file via HTTP can be as fast as possible.

You might know the crate rust-embed: reinda does basically the same, but for the most part has more features and is more flexible (in my opinion).

Tiny example:

use reinda::{assets, Assets, Config, Setup};

const ASSETS: Setup = assets! {
    #![base_path = "assets"]

    "index.html": { template },
    "bundle.js": { hash },
};


let assets = Assets::new(ASSETS, Config::default()).await?;

// Retrieve specific asset. You can now send this data via HTTP or use it however you like.
let bytes /* : Option<bytes::Bytes> */ = assets.get("index.html")?;

See the documentation for more information.

Features

  • Embed files at compile time (in prod mode) or load them at runtime (in dev mode)
  • Allow for dynamic files which will always be loaded at runtime
  • Include content hash in filename (has to be enabled per asset)
  • Template system
    • Include other assets
    • Refer to other assets by path
    • Use runtime variables
  • Compress embedded files to shrink the resulting binary
  • Cargo feature to embed everything in debug mode
  • Template syntax checked at compile time (in prod mode)
  • Well tested

Status of this project

This project is very young. I developed it specifically for a web application I work on where rust-embed did not offer enough features. You should absolutely not use this in production yet, but you sure can try it out.

If you have any thoughts about this project, please let me know in this community feedback issue!



License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~3.5–5MB
~86K SLoC