@@ -5,39 +5,20 @@ use serde::ser::Serialize;
5
5
use serde_json:: value:: { to_value, Map , Value } ;
6
6
7
7
use crate :: errors:: { Error , Result as TeraResult } ;
8
- use crate :: FunctionRelaxed ;
9
- use std:: sync:: Arc ;
10
8
11
9
/// The struct that holds the context of a template rendering.
12
10
///
13
11
/// Light wrapper around a `BTreeMap` for easier insertions of Serializable
14
12
/// values
15
- #[ derive( Clone ) ]
13
+ #[ derive( Debug , Clone , PartialEq ) ]
16
14
pub struct Context {
17
15
data : BTreeMap < String , Value > ,
18
- /// Ignored by PartialEq!
19
- functions : BTreeMap < String , Arc < dyn FunctionRelaxed > > ,
20
- }
21
-
22
- impl std:: fmt:: Debug for Context {
23
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
24
- f. debug_struct ( "Context" )
25
- . field ( "data" , & self . data )
26
- . field ( "functions" , & self . functions . keys ( ) )
27
- . finish ( )
28
- }
29
- }
30
-
31
- impl PartialEq for Context {
32
- fn eq ( & self , other : & Self ) -> bool {
33
- self . data . eq ( & other. data )
34
- }
35
16
}
36
17
37
18
impl Context {
38
19
/// Initializes an empty context
39
20
pub fn new ( ) -> Self {
40
- Context { data : BTreeMap :: new ( ) , functions : Default :: default ( ) }
21
+ Context { data : BTreeMap :: new ( ) }
41
22
}
42
23
43
24
/// Converts the `val` parameter to `Value` and insert it into the context.
@@ -82,15 +63,6 @@ impl Context {
82
63
Ok ( ( ) )
83
64
}
84
65
85
- /// Registers Context-local function
86
- pub fn register_function < T : FunctionRelaxed + ' static , S : Into < String > > (
87
- & mut self ,
88
- key : S ,
89
- val : T ,
90
- ) {
91
- self . functions . insert ( key. into ( ) , Arc :: new ( val) ) ;
92
- }
93
-
94
66
/// Appends the data of the `source` parameter to `self`, overwriting existing keys.
95
67
/// The source context will be dropped.
96
68
///
@@ -125,7 +97,7 @@ impl Context {
125
97
for ( key, value) in m {
126
98
data. insert ( key, value) ;
127
99
}
128
- Ok ( Context { data, functions : Default :: default ( ) } )
100
+ Ok ( Context { data } )
129
101
}
130
102
_ => Err ( Error :: msg (
131
103
"Creating a Context from a Value/Serialize requires it being a JSON object" ,
@@ -155,12 +127,6 @@ impl Context {
155
127
pub fn contains_key ( & self , index : & str ) -> bool {
156
128
self . data . contains_key ( index)
157
129
}
158
-
159
- /// Looks up Context-local registered function
160
- #[ inline]
161
- pub fn get_function ( & self , fn_name : & str ) -> Option < & Arc < dyn FunctionRelaxed > > {
162
- self . functions . get ( fn_name)
163
- }
164
130
}
165
131
166
132
impl Default for Context {
0 commit comments