@@ -97,23 +97,18 @@ impl<'a, 'g> CycleState<'a, 'g> {
9797 }
9898}
9999
100- lazy_static ! {
101- static ref EMPTY_GLOBALS : Object = Object :: new( ) ;
102- }
103-
104100/// Stack of variables.
105101#[ derive( Debug , Clone ) ]
106102pub struct Stack < ' g > {
107- globals : & ' g Globals ,
103+ globals : Option < & ' g Globals > ,
108104 stack : Vec < Object > ,
109105}
110106
111107impl < ' g > Stack < ' g > {
112108 /// Create an empty stack
113109 pub fn empty ( ) -> Self {
114- let empty: & Object = & * EMPTY_GLOBALS ;
115110 Self {
116- globals : empty ,
111+ globals : None ,
117112 // Mutable frame for globals.
118113 stack : vec ! [ Object :: new( ) ] ,
119114 }
@@ -122,7 +117,7 @@ impl<'g> Stack<'g> {
122117 /// Create a stack initialized with read-only `Globals`.
123118 pub fn with_globals ( globals : & ' g Globals ) -> Self {
124119 let mut stack = Self :: empty ( ) ;
125- stack. globals = globals;
120+ stack. globals = Some ( globals) ;
126121 stack
127122 }
128123
@@ -152,7 +147,7 @@ impl<'g> Stack<'g> {
152147 return rval;
153148 }
154149 }
155- self . globals . get ( name)
150+ self . globals . and_then ( |g| g . get ( name) )
156151 }
157152
158153 /// Recursively index into the stack.
@@ -225,23 +220,22 @@ impl<'g> Default for Stack<'g> {
225220
226221/// Create processing context for a template.
227222pub struct ContextBuilder < ' g > {
228- globals : & ' g Globals ,
223+ globals : Option < & ' g Globals > ,
229224 filters : sync:: Arc < HashMap < & ' static str , BoxedValueFilter > > ,
230225}
231226
232227impl < ' g > ContextBuilder < ' g > {
233228 /// Creates a new, empty rendering context.
234229 pub fn new ( ) -> Self {
235- let empty: & Object = & * EMPTY_GLOBALS ;
236230 Self {
237- globals : empty ,
231+ globals : None ,
238232 filters : Default :: default ( ) ,
239233 }
240234 }
241235
242236 /// Initialize the stack with the given globals.
243237 pub fn set_globals ( mut self , values : & ' g Globals ) -> Self {
244- self . globals = values;
238+ self . globals = Some ( values) ;
245239 self
246240 }
247241
@@ -256,8 +250,12 @@ impl<'g> ContextBuilder<'g> {
256250
257251 /// Create the `Context`.
258252 pub fn build ( self ) -> Context < ' g > {
253+ let stack = match self . globals {
254+ Some ( globals) => Stack :: with_globals ( globals) ,
255+ None => Stack :: empty ( ) ,
256+ } ;
259257 Context {
260- stack : Stack :: with_globals ( self . globals ) ,
258+ stack,
261259 interrupt : InterruptState :: default ( ) ,
262260 cycles : CycleStateInner :: default ( ) ,
263261 filters : self . filters ,
0 commit comments