-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds the crate "rinja_derive_standalone", which is just like "rinja_derive", though not a "proc_macro". This way we can easily expose it's internals for testing and benchmarking. Right now, the PR is more or less a prove of concept, and it probably needs a handful more useful benchmark use cases to be worth the hassle.
- Loading branch information
Showing
14 changed files
with
129 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[package] | ||
name = "rinja_derive_standalone" | ||
version = "0.13.0" | ||
description = "Procedural macro package for Rinja" | ||
homepage = "https://github.com/rinja-rs/rinja" | ||
repository = "https://github.com/rinja-rs/rinja" | ||
license = "MIT/Apache-2.0" | ||
workspace = ".." | ||
readme = "README.md" | ||
edition = "2021" | ||
rust-version = "1.65" | ||
publish = false | ||
|
||
[features] | ||
default = ["__standalone"] | ||
__standalone = [] | ||
config = ["serde", "basic-toml"] | ||
humansize = [] | ||
urlencode = [] | ||
serde-json = [] | ||
num-traits = [] | ||
with-actix-web = [] | ||
with-axum = [] | ||
with-rocket = [] | ||
with-warp = [] | ||
|
||
[dependencies] | ||
parser = { package = "rinja_parser", version = "0.3", path = "../rinja_parser" } | ||
mime = "0.3" | ||
mime_guess = "2" | ||
proc-macro2 = "1" | ||
quote = "1" | ||
serde = { version = "1.0", optional = true, features = ["derive"] } | ||
syn = "2" | ||
basic-toml = { version = "0.1.1", optional = true } | ||
|
||
[dev-dependencies] | ||
criterion = "0.5" | ||
|
||
[[bench]] | ||
name = "derive-template" | ||
harness = false | ||
required-features = ["__standalone"] |
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,5 @@ | ||
This crate embeds the source of `rinja_derive`, but is not a `proc_macro`. | ||
This way we can more easily access the internals of the crate. | ||
|
||
To run the benchmark, execute `cargo bench` in this folder, or | ||
`cargo bench -p rinja_derive_standalone` in the project root. |
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,25 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use quote::quote; | ||
|
||
criterion_main!(benches); | ||
criterion_group!(benches, functions); | ||
|
||
fn functions(c: &mut Criterion) { | ||
c.bench_function("hello_world", hello_world); | ||
} | ||
|
||
fn hello_world(b: &mut criterion::Bencher<'_>) { | ||
let ts = quote! { | ||
#[derive(Template)] | ||
#[template( | ||
source = "<html><body><h1>Hello, {{user}}!</h1></body></html>", | ||
ext = "html" | ||
)] | ||
struct Hello<'a> { | ||
user: &'a str, | ||
} | ||
}; | ||
b.iter(|| { | ||
rinja_derive_standalone::derive_template2(black_box(&ts).clone()); | ||
}) | ||
} |
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 @@ | ||
../rinja_derive/src/ |
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 @@ | ||
../rinja_derive/templates/ |