1use crate::Node;
3use std::collections::HashMap;
4
5pub type StateKV = HashMap<Vec<u8>, Vec<u8>>;
7
8pub struct State<W> {
10 pub child: W,
12 pub state: StateKV,
14}
15
16impl<W> State<W>
17where
18 W: Into<Node>,
19{
20 pub fn get(&self, k: &[u8]) -> Vec<u8> {
22 self.state.get(k).unwrap_or(&vec![]).to_vec()
23 }
24
25 pub fn set(&mut self, k: &[u8], v: &[u8]) {
27 self.state.insert(k.to_vec(), v.to_vec());
28 }
29}
30
31impl<W> Into<Node> for State<W>
32where
33 W: Into<Node>,
34{
35 fn into(self) -> Node {
36 let mut n = self.child.into();
37 n.state = Some(self.state);
38 n
39 }
40}