Debian Codegraph @

tests/data_helper.rs

raw symbols SCIP
1 use handlebarsrust-analyzer cargo handlebars 5.1.2 crate/::*;
2 use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::jsonrust-analyzer cargo serde_json 1.0.114 macros/json!;
3
4 struct HelperWithBorrowedDatarust-analyzer cargo handlebars 5.1.2 HelperWithBorrowedData#<'a>(&'a Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#);
5
6 impl<'a> HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# for HelperWithBorrowedDatarust-analyzer cargo handlebars 5.1.2 HelperWithBorrowedData#<'a> {
7 fn callrust-analyzer cargo handlebars 5.1.2 impl#[`HelperWithBorrowedData<'a>`][HelperDef]call().<'_reg: '_rc, '_rc>(
8 &self,
9 _: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'_rc>,
10 _: &'_reg Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#,
11 _: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#,
12 _: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#,
13 out: &mut dyn Outputrust-analyzer cargo handlebars 5.1.2 output/Output#,
14 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
15 out.writerust-analyzer cargo handlebars 5.1.2 output/Output#write().(self.0rust-analyzer cargo handlebars 5.1.2 HelperWithBorrowedData#0.).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<IOError>`]from().)
16 }
17 }
18
19 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
20 fn test_helper_with_ref_datarust-analyzer cargo handlebars 5.1.2 test_helper_with_ref_data().() {
21 let s = "hello helper".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
22 let the_helper = HelperWithBorrowedDatarust-analyzer cargo handlebars 5.1.2 HelperWithBorrowedData#(&s);
23
24 let mut r = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
25 r.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("hello", Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(the_helper));
26
27 let s = r.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("Output: {{hello}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
28 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s, "Output: hello helper".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
29 }