Skip to content

Commit bec3f78

Browse files
committed
remove template library and use format via macro
1 parent 5f14d9c commit bec3f78

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ rand = "0.8.5"
3131
hashbrown = { version = "0.14.3", default-features = false, features = ["serde"] }
3232
pest = "2.8.0"
3333
pest_derive = "2.8.0"
34-
tinytemplate = "1.2.1"
3534

3635
# Uncomment for debugging with https://github.com/ed255/plonky2/ at branch `feat/debug`. The repo directory needs to be checked out next to the pod2 repo directory.
3736
# [patch."https://github.com/0xPolygonZero/plonky2"]

src/examples/custom.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
1-
use std::{collections::HashMap, sync::Arc};
2-
3-
use tinytemplate::TinyTemplate;
1+
use std::sync::Arc;
42

53
use crate::{
64
frontend::Result,
75
lang::parse,
86
middleware::{CustomPredicateBatch, Params, PodType, Value, KEY_SIGNER, KEY_TYPE},
97
};
108

11-
fn render(tmpl: &str, consts: HashMap<&str, Value>) -> String {
12-
let mut tt = TinyTemplate::new();
13-
tt.set_default_formatter(&tinytemplate::format_unescaped);
14-
tt.add_template("tmpl", tmpl).expect("template parse");
15-
16-
let mut context: HashMap<_, Value> = [
17-
("KEY_TYPE", Value::from(KEY_TYPE)),
18-
("KEY_SIGNER", Value::from(KEY_SIGNER)),
19-
]
20-
.into_iter()
21-
.collect();
22-
23-
for (name, value) in consts.into_iter() {
24-
context.insert(name, value);
25-
}
26-
let context: HashMap<_, String> = context
27-
.into_iter()
28-
.map(|(k, v)| (k, format!("{}", v)))
29-
.collect();
30-
tt.render("tmpl", &context).expect("template render")
9+
macro_rules! render {
10+
($tmpl: expr, $($arg:tt)*) => {{
11+
format!(
12+
$tmpl,
13+
KEY_TYPE = Value::from(KEY_TYPE),
14+
KEY_SIGNER = Value::from(KEY_SIGNER),
15+
$($arg)*
16+
)
17+
}};
3118
}
3219

3320
/// Instantiates an ETHDos batch
@@ -37,8 +24,7 @@ pub fn eth_dos_batch(params: &Params, mock: bool) -> Result<Arc<CustomPredicateB
3724
} else {
3825
PodType::Signed
3926
});
40-
let consts = [("pod_type", pod_type)].into_iter().collect();
41-
let input = render(
27+
let input = render!(
4228
r#"
4329
eth_friend(src, dst, private: attestation_pod) = AND(
4430
Equal(?attestation_pod[{KEY_TYPE}], {pod_type})
@@ -62,7 +48,7 @@ pub fn eth_dos_batch(params: &Params, mock: bool) -> Result<Arc<CustomPredicateB
6248
eth_dos_ind(?src, ?dst, ?distance)
6349
)
6450
"#,
65-
consts,
51+
pod_type = pod_type,
6652
);
6753
let batch = parse(&input, params, &[]).expect("lang parse").custom_batch;
6854
println!("a.0. {}", batch.predicates[0]);

0 commit comments

Comments
 (0)