René Kijewski 78eb3579c9 derive: replace ahash with rustc-hash
`ahash` shines when you hash very long inputs, in excess of 1000 bytes.
We only hash file names, variable names, block names … which should for
all reasonable applications less than 100 bytes in length.

`rustc-hash` does not claim to be DoS-resistent like `ahash` is, but we
only operate on trusted data, so this feature is not needed.

See also: <https://blog.goose.love/posts/rosetta-hashing/>.

The performance is mostly unchanged or slightly improved:

```text
hello_world             time:   [61.157 µs 61.336 µs 61.503 µs]
                        change: [-3.5829% -2.8333% -2.0098%] (p = 0.00 < 0.05)
                        Performance has improved.

item_info.html          time:   [69.987 µs 70.137 µs 70.277 µs]
                        change: [-2.5459% -2.1263% -1.7360%] (p = 0.00 < 0.05)
                        Performance has improved.

item_union.html         time:   [185.41 µs 185.80 µs 186.18 µs]
                        change: [-2.9272% -2.4197% -1.9278%] (p = 0.00 < 0.05)
                        Performance has improved.

page.html               time:   [747.83 µs 748.66 µs 749.58 µs]
                        change: [-0.3883% -0.1132% +0.1551%] (p = 0.43 > 0.05)
                        No change in performance detected.

print_item.html         time:   [158.28 µs 158.72 µs 159.28 µs]
                        change: [-1.9084% -1.4402% -0.9742%] (p = 0.00 < 0.05)
                        Change within noise threshold.

short_item_info.html    time:   [133.45 µs 133.66 µs 133.89 µs]
                        change: [-4.0600% -3.7956% -3.5459%] (p = 0.00 < 0.05)
                        Performance has improved.

sidebar.html            time:   [207.27 µs 207.74 µs 208.28 µs]
                        change: [-3.7883% -3.2903% -2.8108%] (p = 0.00 < 0.05)
                        Performance has improved.

source.html             time:   [122.85 µs 123.15 µs 123.53 µs]
                        change: [-1.0462% -0.5575% -0.0943%] (p = 0.03 < 0.05)
                        Change within noise threshold.

type_layout.html        time:   [158.98 µs 159.46 µs 160.00 µs]
                        change: [+0.5711% +0.9257% +1.2877%] (p = 0.00 < 0.05)
                        Change within noise threshold.

type_layout_size.html   time:   [75.699 µs 75.978 µs 76.250 µs]
                        change: [-2.6748% -1.9573% -1.0695%] (p = 0.00 < 0.05)
                        Performance has improved.
```
2024-08-16 16:56:18 +02:00
2024-08-13 19:17:37 +02:00
2024-08-13 19:17:37 +02:00
2021-02-05 10:47:35 +01:00
2024-07-04 07:05:57 +02:00
2024-08-13 18:27:29 +02:00
2024-08-08 23:02:13 +02:00
2024-08-13 19:17:37 +02:00

rinja

Crates.io GitHub Workflow Status Book docs.rs

Rinja implements a template rendering engine based on Jinja, and generates type-safe Rust code from your templates at compile time based on a user-defined struct to hold the template's context. See below for an example. It is a fork of Askama.

All feedback welcome! Feel free to file bugs, requests for documentation and any other feedback to the issue tracker.

You can find the documentation about our syntax, features, configuration in our book: rinja.readthedocs.io.

Have a look at our Rinja Playground, if you want to try out rinja's code generation online.

Feature highlights

  • Construct templates using a familiar, easy-to-use syntax
  • Benefit from the safety provided by Rust's type system
  • Template code is compiled into your crate for optimal performance
  • Optional built-in support for Actix, Axum, Rocket, and warp web frameworks
  • Debugging features to assist you in template development
  • Templates must be valid UTF-8 and produce UTF-8 when rendered
  • Works on stable Rust

Supported in templates

  • Template inheritance
  • Loops, if/else statements and include support
  • Macro support
  • Variables (no mutability allowed)
  • Some built-in filters, and the ability to use your own
  • Whitespace suppressing with '-' markers
  • Opt-out HTML escaping
  • Syntax customization

How to get started

First, add the rinja dependency to your crate's Cargo.toml:

cargo add rinja

Now create a directory called templates in your crate root. In it, create a file called hello.html, containing the following:

Hello, {{ name }}!

In any Rust file inside your crate, add the following:

use rinja::Template; // bring trait in scope

#[derive(Template)] // this will generate the code...
#[template(path = "hello.html")] // using the template in this path, relative
                                 // to the `templates` dir in the crate root
struct HelloTemplate<'a> { // the name of the struct can be anything
    name: &'a str, // the field name should match the variable name
                   // in your template
}

fn main() {
    let hello = HelloTemplate { name: "world" }; // instantiate your struct
    println!("{}", hello.render().unwrap()); // then render it.
}

You should now be able to compile and run this code.

Description
A template rendering engine based on Jinja, generating type-safe Rust code at compile time.
Readme 5.2 MiB
Languages
Rust 92.9%
HTML 3%
JavaScript 2.9%
Python 0.9%
CSS 0.2%