#assets #web-apps #compile-time #embed #information #offers #reinda

macro reinda-macros

Internal crate for reinda. Do not use this crate directly! See the main crate for more information.

4 releases

0.0.4 May 15, 2024
0.0.3 Apr 17, 2023
0.0.2 Jan 27, 2021
0.0.1 Jan 22, 2021

#46 in #offers

Download history 80/week @ 2024-02-26 18/week @ 2024-03-04 16/week @ 2024-03-11 4/week @ 2024-03-18 1/week @ 2024-03-25 37/week @ 2024-04-01 3/week @ 2024-04-08 132/week @ 2024-05-13 31/week @ 2024-05-20 12/week @ 2024-05-27 14/week @ 2024-06-03 9/week @ 2024-06-10

71 downloads per month
Used in reinda

MIT/Apache

18KB
401 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

~0.2–1.7MB
~69K SLoC