summaryrefslogtreecommitdiff
path: root/src/eval/template.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval/template.rs')
-rw-r--r--src/eval/template.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/eval/template.rs b/src/eval/template.rs
index 4fc6985a..f4feda40 100644
--- a/src/eval/template.rs
+++ b/src/eval/template.rs
@@ -140,6 +140,19 @@ impl Template {
self.make_mut().push(TemplateNode::Modify(Rc::new(f)));
}
+ /// Return a new template which is modified from start to end.
+ pub fn modified<F>(self, f: F) -> Self
+ where
+ F: Fn(&mut State) + 'static,
+ {
+ let mut wrapper = Self::new();
+ wrapper.save();
+ wrapper.modify(f);
+ wrapper += self;
+ wrapper.restore();
+ wrapper
+ }
+
/// Build the stack node resulting from instantiating the template in the
/// given state.
pub fn to_stack(&self, state: &State) -> StackNode {