-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from Kijewski/pr-no-derive
Make `derive` optional
- Loading branch information
Showing
22 changed files
with
212 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.rustfmt.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "bench-build" | ||
version = "0.3.5" | ||
authors = ["rinja-rs developers"] | ||
edition = "2021" | ||
rust-version = "1.81" | ||
publish = false | ||
|
||
[dependencies] | ||
rinja = { path = "../rinja", version = "0.3.5", default-features = false, features = ["std"] } | ||
rinja_derive = { path = "../rinja_derive", version = "0.3.5", features = ["std"] } | ||
|
||
[features] | ||
default = [] | ||
derive = ["rinja/derive"] | ||
|
||
[workspace] | ||
members = ["."] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-APACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Run the script `./run.sh` in this directory to compare the compile compile of `rinja` | ||
|
||
* uses feature `derive` vs | ||
* it does not use that feature. | ||
|
||
The output might look like: | ||
|
||
```text | ||
Benchmark 1: cargo run --features=derive | ||
Time (mean ± σ): 3.378 s ± 0.041 s [User: 7.944 s, System: 1.018 s] | ||
Range (min … max): 3.345 s … 3.424 s 3 runs | ||
Benchmark 2: cargo run | ||
Time (mean ± σ): 3.283 s ± 0.130 s [User: 8.400 s, System: 1.091 s] | ||
Range (min … max): 3.141 s … 3.398 s 3 runs | ||
Summary | ||
cargo run ran | ||
1.03 ± 0.04 times faster than cargo run --features=derive | ||
---------- | ||
Benchmark 1: cargo run --release --features=derive | ||
Time (mean ± σ): 4.733 s ± 0.050 s [User: 9.026 s, System: 0.749 s] | ||
Range (min … max): 4.689 s … 4.788 s 3 runs | ||
Benchmark 2: cargo run --release | ||
Time (mean ± σ): 4.504 s ± 0.032 s [User: 9.010 s, System: 0.733 s] | ||
Range (min … max): 4.481 s … 4.541 s 3 runs | ||
Summary | ||
cargo run --release ran | ||
1.05 ± 0.01 times faster than cargo run --release --features=derive | ||
``` | ||
|
||
This shows that – while it is less convenient – for small projects it might be better | ||
to use the following setup. | ||
This might be especially true if you are using `rinja` in a library. | ||
Without the feature, `cargo` will be able to compile more dependencies in parallel. | ||
|
||
```toml | ||
# Cargo.toml | ||
[dependencies] | ||
rinja = { version = "0.3.5", default-features = false, features = ["std"] } | ||
rinja_derive = { version = "0.3.5", features = ["std"] } | ||
``` | ||
|
||
```rust | ||
// lib.rs | ||
use rinja::Template as _; | ||
use rinja_derive::Template; | ||
``` | ||
|
||
The script uses [hyperfine](https://crates.io/crates/hyperfine). | ||
Install it with `cargo install hyperfine`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../_typos.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../clippy.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../deny.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
|
||
mkdir -p target | ||
hyperfine \ | ||
--runs=3 \ | ||
--warmup=1 \ | ||
--prepare='rm -r target' \ | ||
'cargo run --features=derive' \ | ||
'cargo run' | ||
echo | ||
echo ---------- | ||
echo | ||
hyperfine \ | ||
--runs=3 \ | ||
--warmup=1 \ | ||
--prepare='rm -r target' \ | ||
'cargo run --release --features=derive' \ | ||
'cargo run --release' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::str::FromStr; | ||
|
||
use rinja::Template as _; | ||
use rinja_derive::Template; | ||
|
||
fn main() { | ||
let mut args = std::env::args().fuse().skip(1); | ||
let greeting = args.next(); | ||
let user = args.next(); | ||
|
||
let tmpl = HelloWorld { | ||
greeting: greeting.as_deref().unwrap_or("hi").parse().unwrap(), | ||
user: user.as_deref().unwrap_or("user"), | ||
}; | ||
println!("{}", tmpl.render().unwrap()); | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Template)] | ||
#[template(path = "hello_world.html")] | ||
struct HelloWorld<'a> { | ||
greeting: Greeting, | ||
user: &'a str, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Template)] | ||
#[template(path = "greeting.html")] | ||
enum Greeting { | ||
#[template(block = "hello")] | ||
Hello, | ||
#[template(block = "hey")] | ||
Hey, | ||
#[template(block = "hi")] | ||
Hi, | ||
} | ||
|
||
impl FromStr for Greeting { | ||
type Err = &'static str; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"hello" => Ok(Self::Hello), | ||
"hey" => Ok(Self::Hey), | ||
"hi" => Ok(Self::Hi), | ||
_ => Err("Valid greetings: <hello | hey | hi>"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{%- block hello -%} | ||
Hello | ||
{%- endblock -%} | ||
|
||
{%- block hey -%} | ||
Hey | ||
{%- endblock -%} | ||
|
||
{%- block hi -%} | ||
Hi | ||
{%- endblock -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>{{greeting}}, {{user}}!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../tomlfmt.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters