blob: 3fb874e2b077c6935dbcea14fc3d57ebee993717 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
extern crate env_logger;
extern crate handlebars;
#[macro_use]
extern crate serde_json;
use std::error::Error;
use handlebars::Handlebars;
fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
let mut handlebars = Handlebars::new();
// template not found
println!(
"{}",
handlebars
.register_template_file("notfound", "./examples/error/notfound.hbs")
.unwrap_err()
);
// an invalid templat
println!(
"{}",
handlebars
.register_template_file("error", "./examples/error/error.hbs")
.unwrap_err()
);
// render error
let e1 = handlebars
.render_template("{{#if}}", &json!({}))
.unwrap_err();
let be1 = Box::new(e1);
println!("{}", be1);
println!("{}", be1.source().unwrap());
println!("{:?}", be1.source().unwrap().source());
Ok(())
}
|