use crate::ops::{Op, OpKind};
use super::map_state::MapState;
pub(crate) struct MapTranslator {
pub(super) map: MapState,
}
impl MapTranslator {
pub fn new(map: MapState) -> MapTranslator {
MapTranslator { map }
}
pub fn iter_entries(&self) -> impl Iterator<Item = (String, litl::Val)> + '_ {
self.map.ops_for_key.keys().filter_map(move |key| {
let maybe_last_op = self.map.last_op_for_key_not_undone(key);
match maybe_last_op {
Some(Op {
kind: OpKind::MapSet,
val: Some(entry),
..
}) => Some((entry[0].as_str().unwrap().to_owned(), entry[1].clone())),
_ => None,
}
})
}
}
impl std::ops::Deref for MapTranslator {
type Target = MapState;
fn deref(&self) -> &Self::Target {
&self.map
}
}