Debian Codegraph @

src/context.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::{HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#};
2
3 use serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#;
4 use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::valuerust-analyzer cargo serde_json 1.0.114 value/::{to_valuerust-analyzer cargo serde_json 1.0.114 value/to_value()., Maprust-analyzer cargo serde_json 1.0.114 map/Map#, Valuerust-analyzer cargo serde_json 1.0.114 value/Value# as Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#};
5
6 use craterust-analyzer cargo handlebars 5.1.2 crate/::blockrust-analyzer cargo handlebars 5.1.2 block/::{BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#, BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#};
7 use craterust-analyzer cargo handlebars 5.1.2 crate/::errorrust-analyzer cargo handlebars 5.1.2 error/::{RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#, RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#};
8 use craterust-analyzer cargo handlebars 5.1.2 crate/::grammarrust-analyzer cargo handlebars 5.1.2 grammar/::Rulerust-analyzer cargo handlebars 5.1.2 grammar/Rule#;
9 use craterust-analyzer cargo handlebars 5.1.2 crate/::jsonrust-analyzer cargo handlebars 5.1.2 json/::pathrust-analyzer cargo handlebars 5.1.2 json/path/::*;
10 use craterust-analyzer cargo handlebars 5.1.2 crate/::jsonrust-analyzer cargo handlebars 5.1.2 json/::valuerust-analyzer cargo handlebars 5.1.2 json/value/::ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#;
11 use craterust-analyzer cargo handlebars 5.1.2 crate/::utilrust-analyzer cargo handlebars 5.1.2 util/::extendrust-analyzer cargo handlebars 5.1.2 util/extend().;
12
13 pub type Objectrust-analyzer cargo handlebars 5.1.2 context/Object# = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#>;
14
15 /// The context wrap data you render on your templates.
16 ///
17 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
18 pub struct Contextrust-analyzer cargo handlebars 5.1.2 context/Context# {
19 datarust-analyzer cargo handlebars 5.1.2 context/Context#data.: Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#,
20 }
21
22 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
23 enum ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#<'a> {
24 // FIXME: change to borrowed when possible
25 // full path
26 AbsolutePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#AbsolutePath#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
27 // relative path and path root
28 RelativePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#RelativePath#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
29 // relative path against block param value
30 BlockParamValuerust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#BlockParamValue#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, &'a Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#),
31 // relative path against derived value,
32 LocalValuerust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#LocalValue#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, &'a Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#),
33 }
34
35 fn parse_json_visitorrust-analyzer cargo handlebars 5.1.2 context/parse_json_visitor().<'a>(
36 relative_path: &[PathSegrust-analyzer cargo handlebars 5.1.2 json/path/PathSeg#],
37 block_contexts: &'a VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'_>>,
38 always_for_absolute_path: bool,
39 ) -> ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#<'a> {
40 let mut path_context_depth: i64 = 0;
41 let mut with_block_param = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
42 let mut from_root = false;
43
44 // peek relative_path for block param, @root and "../../"
45 for path_seg in relative_path {
46 match path_seg {
47 PathSegrust-analyzer cargo handlebars 5.1.2 json/path/PathSeg#::Namedrust-analyzer cargo handlebars 5.1.2 json/path/PathSeg#Named#(the_path) => {
48 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((holder, base_path)) = get_in_block_paramsrust-analyzer cargo handlebars 5.1.2 context/get_in_block_params().(block_contexts, the_path) {
49 with_block_param = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((holder, base_path));
50 }
51 break;
52 }
53 PathSegrust-analyzer cargo handlebars 5.1.2 json/path/PathSeg#::Ruledrust-analyzer cargo handlebars 5.1.2 json/path/PathSeg#Ruled#(the_rule) => match the_rule {
54 Rulerust-analyzer cargo handlebars 5.1.2 grammar/Rule#::path_rootrust-analyzer cargo handlebars 5.1.2 grammar/Rule#path_root# => {
55 from_root = true;
56 break;
57 }
58 Rulerust-analyzer cargo handlebars 5.1.2 grammar/Rule#::path_uprust-analyzer cargo handlebars 5.1.2 grammar/Rule#path_up# => path_context_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().1,
59 _ => break,
60 },
61 }
62 }
63
64 let mut path_stack = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(relative_path.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().5);
65 match with_block_param {
66 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#::Valuerust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#Value#(ref value), _)) => {
67 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, &relative_path[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
68 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::BlockParamValuerust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#BlockParamValue#(path_stack, value)
69 }
70 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#::Pathrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#Path#(ref paths), base_path)) => {
71 extendrust-analyzer cargo handlebars 5.1.2 util/extend().(&mut path_stack, base_path);
72 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().paths.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
73 extendrust-analyzer cargo handlebars 5.1.2 util/extend().(&mut path_stack, paths);
74 }
75 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, &relative_path[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
76
77 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::AbsolutePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#AbsolutePath#(path_stack)
78 }
79 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
80 if path_context_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt().0 {
81 let blk = block_contexts
82 .getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]get().(path_context_depth as usize)
83 .or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| block_contexts.frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]front().());
84
85 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base_value) = blk.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|blk| blk.base_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_value().()) {
86 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, relative_path);
87 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::LocalValuerust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#LocalValue#(path_stack, base_value)
88 } else {
89 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base_path) = blk.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|blk| blk.base_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path().()) {
90 extendrust-analyzer cargo handlebars 5.1.2 util/extend().(&mut path_stack, base_path);
91 }
92 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, relative_path);
93 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::AbsolutePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#AbsolutePath#(path_stack)
94 }
95 } else if from_root {
96 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, relative_path);
97 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::AbsolutePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#AbsolutePath#(path_stack)
98 } else if always_for_absolute_path {
99 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base_value) = block_contexts.frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]front().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|blk| blk.base_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_value().()) {
100 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, relative_path);
101 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::LocalValuerust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#LocalValue#(path_stack, base_value)
102 } else {
103 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base_path) = block_contexts.frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]front().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|blk| blk.base_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path().()) {
104 extendrust-analyzer cargo handlebars 5.1.2 util/extend().(&mut path_stack, base_path);
105 }
106 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, relative_path);
107 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::AbsolutePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#AbsolutePath#(path_stack)
108 }
109 } else {
110 merge_json_pathrust-analyzer cargo handlebars 5.1.2 json/path/merge_json_path().(&mut path_stack, relative_path);
111 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::RelativePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#RelativePath#(path_stack)
112 }
113 }
114 }
115 }
116
117 fn get_datarust-analyzer cargo handlebars 5.1.2 context/get_data().<'a>(d: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#>, p: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
118 let result = match d {
119 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.114 value/Value#Array#(l)) => p
120 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<usize>()
121 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|idx_u| l.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(idx_u))
122 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::InvalidJsonIndexrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#InvalidJsonIndex#(p.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
123 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::Objectrust-analyzer cargo serde_json 1.0.114 value/Value#Object#(m)) => m.getrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]get().(p),
124 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
125 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
126 };
127 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result)
128 }
129
130 fn get_in_block_paramsrust-analyzer cargo handlebars 5.1.2 context/get_in_block_params().<'a>(
131 block_contexts: &'a VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'_>>,
132 p: &str,
133 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(&'a BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#, &'a Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>)> {
134 for bc in block_contexts {
135 let v = bc.get_block_paramrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]get_block_param().(p);
136 if v.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
137 return v.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| (v, bc.base_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path().()));
138 }
139 }
140
141 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
142 }
143
144 pub(craterust-analyzer cargo handlebars 5.1.2 crate/) fn merge_jsonrust-analyzer cargo handlebars 5.1.2 context/merge_json().(base: &Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#, addition: &HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&str, &Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#>) -> Jsonrust-analyzer cargo serde_json 1.0.114 value/Value# {
145 let mut base_map = match base {
146 Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::Objectrust-analyzer cargo serde_json 1.0.114 value/Value#Object#(ref m) => m.clonerust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`][Clone]clone().(),
147 _ => Maprust-analyzer cargo serde_json 1.0.114 map/Map#::newrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]new().(),
148 };
149
150 for (k, v) in addition.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() {
151 base_map.insertrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]insert().(k.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v).clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().());
152 }
153
154 Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::Objectrust-analyzer cargo serde_json 1.0.114 value/Value#Object#(base_map)
155 }
156
157 impl Contextrust-analyzer cargo handlebars 5.1.2 context/Context# {
158 /// Create a context with null data
159 pub fn nullrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]null().() -> Contextrust-analyzer cargo handlebars 5.1.2 context/Context# {
160 Contextrust-analyzer cargo handlebars 5.1.2 context/Context# { datarust-analyzer cargo handlebars 5.1.2 context/Context#data.: Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::Nullrust-analyzer cargo serde_json 1.0.114 value/Value#Null# }
161 }
162
163 /// Create a context with given data
164 pub fn wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().<T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#>(e: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
165 to_valuerust-analyzer cargo serde_json 1.0.114 value/to_value().(e)
166 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::SerdeErrorrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#SerdeError#(e).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
167 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|d| Contextrust-analyzer cargo handlebars 5.1.2 context/Context# { datarust-analyzer cargo handlebars 5.1.2 context/Context#data.: d })
168 }
169
170 /// Navigate the context with relative path and block scopes
171 pub(craterust-analyzer cargo handlebars 5.1.2 crate/) fn navigaterust-analyzer cargo handlebars 5.1.2 context/impl#[Context]navigate().<'rc>(
172 &'rc self,
173 relative_path: &[PathSegrust-analyzer cargo handlebars 5.1.2 json/path/PathSeg#],
174 block_contexts: &VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'_>>,
175 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#<'rc>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
176 // always use absolute at the moment until we get base_value lifetime issue fixed
177 let resolved_visitor = parse_json_visitorrust-analyzer cargo handlebars 5.1.2 context/parse_json_visitor().(relative_path, block_contexts, true);
178
179 match resolved_visitor {
180 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::AbsolutePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#AbsolutePath#(paths) => {
181 let mut ptr = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.datarust-analyzer cargo handlebars 5.1.2 context/impl#[Context]data().());
182 for p in paths.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
183 ptr = get_datarust-analyzer cargo handlebars 5.1.2 context/get_data().(ptr, p)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
184 }
185
186 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ptr
187 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#::Contextrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#Context#(v, paths))
188 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#::Missingrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#Missing#))
189 }
190 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::RelativePathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#RelativePath#(_paths) => {
191 // relative path is disabled for now
192 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!()
193 // let mut ptr = block_contexts.front().and_then(|blk| blk.base_value());
194 // for p in paths.iter() {
195 // ptr = get_data(ptr, p)?;
196 // }
197
198 // Ok(ptr
199 // .map(|v| ScopedJson::Context(v, paths))
200 // .unwrap_or_else(|| ScopedJson::Missing))
201 }
202 ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::BlockParamValuerust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#BlockParamValue#(paths, value)
203 | ResolvedPathrust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#::LocalValuerust-analyzer cargo handlebars 5.1.2 context/ResolvedPath#LocalValue#(paths, value) => {
204 let mut ptr = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value);
205 for p in paths.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
206 ptr = get_datarust-analyzer cargo handlebars 5.1.2 context/get_data().(ptr, p)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
207 }
208 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ptr
209 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#::Derivedrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#Derived#(v.clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().()))
210 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#::Missingrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#Missing#))
211 }
212 }
213 }
214
215 /// Return the Json data wrapped in context
216 pub fn datarust-analyzer cargo handlebars 5.1.2 context/impl#[Context]data().(&self) -> &Jsonrust-analyzer cargo serde_json 1.0.114 value/Value# {
217 &self.datarust-analyzer cargo handlebars 5.1.2 context/Context#data.
218 }
219
220 /// Return the mutable reference to Json data wrapped in context
221 pub fn data_mutrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]data_mut().(&mut self) -> &mut Jsonrust-analyzer cargo serde_json 1.0.114 value/Value# {
222 &mut self.datarust-analyzer cargo handlebars 5.1.2 context/Context#data.
223 }
224 }
225
226 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#> for Contextrust-analyzer cargo handlebars 5.1.2 context/Context# {
227 fn fromrust-analyzer cargo handlebars 5.1.2 context/impl#[Context][`From<Json>`]from().(data: Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#) -> Contextrust-analyzer cargo handlebars 5.1.2 context/Context# {
228 Contextrust-analyzer cargo handlebars 5.1.2 context/Context# { datarust-analyzer cargo handlebars 5.1.2 context/Context#data. }
229 }
230 }
231
232 #[cfg(test)]
233 mod testrust-analyzer cargo handlebars 5.1.2 context/test/ {
234 use craterust-analyzer cargo handlebars 5.1.2 crate/::blockrust-analyzer cargo handlebars 5.1.2 block/::{BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#, BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#};
235 use craterust-analyzer cargo handlebars 5.1.2 crate/::contextrust-analyzer cargo handlebars 5.1.2 context/::{selfrust-analyzer cargo handlebars 5.1.2 context/, Contextrust-analyzer cargo handlebars 5.1.2 context/Context#};
236 use craterust-analyzer cargo handlebars 5.1.2 crate/::errorrust-analyzer cargo handlebars 5.1.2 error/::RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#;
237 use craterust-analyzer cargo handlebars 5.1.2 crate/::jsonrust-analyzer cargo handlebars 5.1.2 json/::pathrust-analyzer cargo handlebars 5.1.2 json/path/::Pathrust-analyzer cargo handlebars 5.1.2 json/path/Path#;
238 use craterust-analyzer cargo handlebars 5.1.2 crate/::jsonrust-analyzer cargo handlebars 5.1.2 json/::valuerust-analyzer cargo handlebars 5.1.2 json/value/::{selfrust-analyzer cargo handlebars 5.1.2 json/value/, ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#};
239 use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::valuerust-analyzer cargo serde_json 1.0.114 value/::Maprust-analyzer cargo serde_json 1.0.114 map/Map#;
240 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::{HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#};
241
242 fn navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().<'reg, 'rc>(
243 ctx: &'rc Contextrust-analyzer cargo handlebars 5.1.2 context/Context#,
244 path: &str,
245 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#<'rc>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
246 let relative_path = Pathrust-analyzer cargo handlebars 5.1.2 json/path/Path#::parserust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]parse().(path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
247 ctx.navigaterust-analyzer cargo handlebars 5.1.2 context/impl#[Context]navigate().(relative_path.segsrust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]segs().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), &VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().())
248 }
249
250 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:)]
251 struct Addressrust-analyzer cargo handlebars 5.1.2 context/test/Address# {
252 cityrust-analyzer cargo handlebars 5.1.2 context/test/Address#city.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
253 countryrust-analyzer cargo handlebars 5.1.2 context/test/Address#country.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
254 }
255
256 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:)]
257 struct Personrust-analyzer cargo handlebars 5.1.2 context/test/Person# {
258 namerust-analyzer cargo handlebars 5.1.2 context/test/Person#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
259 agerust-analyzer cargo handlebars 5.1.2 context/test/Person#age.: i16,
260 addrrust-analyzer cargo handlebars 5.1.2 context/test/Person#addr.: Addressrust-analyzer cargo handlebars 5.1.2 context/test/Address#,
261 titlesrust-analyzer cargo handlebars 5.1.2 context/test/Person#titles.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
262 }
263
264 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
265 fn test_renderrust-analyzer cargo handlebars 5.1.2 context/test/test_render().() {
266 let v = "hello";
267 let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&v.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
268 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
269 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx, "this").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
270 v.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
271 );
272 }
273
274 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
275 fn test_navigationrust-analyzer cargo handlebars 5.1.2 context/test/test_navigation().() {
276 let addr = Addressrust-analyzer cargo handlebars 5.1.2 context/test/Address# {
277 cityrust-analyzer cargo handlebars 5.1.2 context/test/Address#city.: "Beijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
278 countryrust-analyzer cargo handlebars 5.1.2 context/test/Address#country.: "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
279 };
280
281 let person = Personrust-analyzer cargo handlebars 5.1.2 context/test/Person# {
282 namerust-analyzer cargo handlebars 5.1.2 context/test/Person#name.: "Ning Sun".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
283 agerust-analyzer cargo handlebars 5.1.2 context/test/Person#age.: 27,
284 addrrust-analyzer cargo handlebars 5.1.2 context/test/Person#addr.,
285 titlesrust-analyzer cargo handlebars 5.1.2 context/test/Person#titles.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["programmer".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "cartographer".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
286 };
287
288 let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&person).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
289 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
290 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx, "./addr/country").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
291 "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
292 );
293 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
294 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx, "addr.[country]").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
295 "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
296 );
297
298 let v = true;
299 let ctx2 = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&v).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
300 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
301 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx2, "this").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
302 "true".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
303 );
304
305 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
306 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx, "titles.[0]").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
307 "programmer".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
308 );
309
310 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
311 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx, "age").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
312 "27".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
313 );
314 }
315
316 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
317 fn test_thisrust-analyzer cargo handlebars 5.1.2 context/test/test_this().() {
318 let mut map_with_this = Maprust-analyzer cargo serde_json 1.0.114 map/Map#::newrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]new().();
319 map_with_this.insertrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]insert().("this".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), valuerust-analyzer cargo handlebars 5.1.2 json/value/::to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().("hello"));
320 map_with_this.insertrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]insert().("age".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), valuerust-analyzer cargo handlebars 5.1.2 json/value/::to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(5usize));
321 let ctx1 = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&map_with_this).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
322
323 let mut map_without_this = Maprust-analyzer cargo serde_json 1.0.114 map/Map#::newrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]new().();
324 map_without_this.insertrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]insert().("age".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), valuerust-analyzer cargo handlebars 5.1.2 json/value/::to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(4usize));
325 let ctx2 = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&map_without_this).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
326
327 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
328 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx1, "this").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
329 "[object]".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
330 );
331 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
332 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx2, "age").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
333 "4".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
334 );
335 }
336
337 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
338 fn test_merge_jsonrust-analyzer cargo handlebars 5.1.2 context/test/test_merge_json().() {
339 let map = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ "age": 4 });
340 let s = "hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
341 let mut hash = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
342 let v = valuerust-analyzer cargo handlebars 5.1.2 json/value/::to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().("h1");
343 hash.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("tag", &v);
344
345 let ctx_a1 = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&contextrust-analyzer cargo handlebars 5.1.2 context/::merge_jsonrust-analyzer cargo handlebars 5.1.2 context/merge_json().(&map, &hash)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
346 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
347 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx_a1, "age").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
348 "4".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
349 );
350 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
351 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx_a1, "tag").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
352 "h1".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
353 );
354
355 let ctx_a2 = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&contextrust-analyzer cargo handlebars 5.1.2 context/::merge_jsonrust-analyzer cargo handlebars 5.1.2 context/merge_json().(&valuerust-analyzer cargo handlebars 5.1.2 json/value/::to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(s), &hash)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
356 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
357 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx_a2, "this").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
358 "[object]".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
359 );
360 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
361 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx_a2, "tag").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
362 "h1".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
363 );
364 }
365
366 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
367 fn test_key_name_with_thisrust-analyzer cargo handlebars 5.1.2 context/test/test_key_name_with_this().() {
368 let m = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
369 "this_name": "the_value"
370 });
371 let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&m).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
372 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
373 navigate_from_rootrust-analyzer cargo handlebars 5.1.2 context/test/navigate_from_root().(&ctx, "this_name").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
374 "the_value".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
375 );
376 }
377
378 use serderust-analyzer cargo serde 1.0.229 crate/::serrust-analyzer cargo serde_core 1.0.229 ser/::Errorrust-analyzer cargo serde_core 1.0.229 ser/Error# as SerdeErrorrust-analyzer cargo serde_core 1.0.229 ser/Error#;
379 use serderust-analyzer cargo serde 1.0.229 crate/::{Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#};
380
381 struct UnserializableTyperust-analyzer cargo handlebars 5.1.2 context/test/UnserializableType# {}
382
383 impl Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for UnserializableTyperust-analyzer cargo handlebars 5.1.2 context/test/UnserializableType# {
384 fn serializerust-analyzer cargo handlebars 5.1.2 context/test/impl#[UnserializableType][Serialize]serialize().<S>(&self, _: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#>
385 where
386 S: Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#,
387 {
388 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(SerdeErrorrust-analyzer cargo serde_core 1.0.229 ser/Error#::customrust-analyzer cargo serde_core 1.0.229 ser/Error#custom().("test"))
389 }
390 }
391
392 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
393 fn test_serialize_errorrust-analyzer cargo handlebars 5.1.2 context/test/test_serialize_error().() {
394 let d = UnserializableTyperust-analyzer cargo handlebars 5.1.2 context/test/UnserializableType# {};
395 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&d).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
396 }
397
398 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
399 fn test_rootrust-analyzer cargo handlebars 5.1.2 context/test/test_root().() {
400 let m = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
401 "a" : {
402 "b" : {
403 "c" : {
404 "d" : 1
405 }
406 }
407 },
408 "b": 2
409 });
410 let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&m).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
411 let mut block = BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]new().();
412 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().block.base_path_mutrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path_mut().() = ["a".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "b".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()].to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
413
414 let mut blocks = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().();
415 blocks.push_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_front().(block);
416
417 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
418 ctx.navigaterust-analyzer cargo handlebars 5.1.2 context/impl#[Context]navigate().(&Pathrust-analyzer cargo handlebars 5.1.2 json/path/Path#::parserust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]parse().("@root/b").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().segsrust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]segs().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), &blocks)
419 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
420 .renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
421 "2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
422 );
423 }
424
425 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
426 fn test_block_paramsrust-analyzer cargo handlebars 5.1.2 context/test/test_block_params().() {
427 let m = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!([{
428 "a": [1, 2]
429 }, {
430 "b": [2, 3]
431 }]);
432
433 let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&m).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
434 let mut block_params = BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]new().();
435 block_params
436 .add_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_path().("z", ["0".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "a".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()].to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().())
437 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
438 block_params.add_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_value().("t", jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!("good")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
439
440 let mut block = BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]new().();
441 block.set_block_paramsrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_block_params().(block_params);
442
443 let mut blocks = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().();
444 blocks.push_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_front().(block);
445
446 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
447 ctx.navigaterust-analyzer cargo handlebars 5.1.2 context/impl#[Context]navigate().(&Pathrust-analyzer cargo handlebars 5.1.2 json/path/Path#::parserust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]parse().("z.[1]").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().segsrust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]segs().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), &blocks)
448 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
449 .renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
450 "2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
451 );
452 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
453 ctx.navigaterust-analyzer cargo handlebars 5.1.2 context/impl#[Context]navigate().(&Pathrust-analyzer cargo handlebars 5.1.2 json/path/Path#::parserust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]parse().("t").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().segsrust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]segs().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), &blocks)
454 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
455 .renderrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]render().(),
456 "good".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
457 );
458 }
459 }