use std::collections::HashMap;
pub type Ctx<S> = HashMap<String, S>;
#[derive(Clone)]
pub struct CtxMgr<S> {
global: Ctx<S>,
}
impl<S> CtxMgr<S> where S: Clone {
pub(crate) fn new() -> Self {
Self { global: Ctx::default() }
}
pub(crate) fn insert(&mut self, name: String, s: S) {
self.global.insert(name, s);
}
pub(crate) fn filter(&self, names: Vec<String>) -> Ctx<S> {
names.iter().filter_map(|name| Some((name.clone(), (*self.global.get(name)?).clone()))).collect()
}
}