1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{Bindings, Kurinji};

impl Kurinji {
    /// Push bindings to stack
    pub fn push(&mut self, bindings: Bindings) {
        // store current in stack
        let current = self.get_bindings();
        self.stack.push(current);

        // set new config as current
        self.set_bindings(bindings);
    }

    /// Clones current bindings and pushes it with the new
    /// changes
    pub fn push_additive(&mut self, bindings: Bindings) {
        // store current in stack
        let current = self.get_bindings();
        self.stack.push(current);

        // additive merge
        let mut new_binding = self.stack.last().unwrap().clone();
        new_binding.merge(bindings);

        // set new config as current
        self.set_bindings(new_binding);
    }

    /// Pop the current binding from stack
    pub fn pop(&mut self) {
        if let Some(next) = self.stack.pop() {
            self.set_bindings(next);
        }
    }
}