File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,25 @@ impl HashMapContext {
209
209
pub fn clear_functions ( & mut self ) {
210
210
self . functions . clear ( )
211
211
}
212
+
213
+ /// Removes all variables and functions from the context.
214
+ /// This allows to reuse the context without allocating a new HashMap.
215
+ ///
216
+ /// # Example
217
+ ///
218
+ /// ```rust
219
+ /// # use evalexpr::*;
220
+ ///
221
+ /// let mut context = HashMapContext::new();
222
+ /// context.set_value("abc".into(), "def".into()).unwrap();
223
+ /// assert_eq!(context.get_value("abc"), Some(&("def".into())));
224
+ /// context.clear();
225
+ /// assert_eq!(context.get_value("abc"), None);
226
+ /// ```
227
+ pub fn clear ( & mut self ) {
228
+ self . clear_variables ( ) ;
229
+ self . clear_functions ( ) ;
230
+ }
212
231
}
213
232
214
233
impl Context for HashMapContext {
You can’t perform that action at this time.
0 commit comments