use crate::Node;
use std::collections::HashMap;
pub type StateKV = HashMap<Vec<u8>, Vec<u8>>;
pub struct State<W> {
pub child: W,
pub state: StateKV,
}
impl<W> State<W>
where
W: Into<Node>,
{
pub fn get(&self, k: &[u8]) -> Vec<u8> {
self.state.get(k).unwrap_or(&vec![]).to_vec()
}
pub fn set(&mut self, k: &[u8], v: &[u8]) {
self.state.insert(k.to_vec(), v.to_vec());
}
}
impl<W> Into<Node> for State<W>
where
W: Into<Node>,
{
fn into(self) -> Node {
let mut n = self.child.into();
n.state = Some(self.state);
n
}
}