use std::collections::HashMap;
use crate::{
connection::information_packet::Content,
node::{NODE_TABLE_STR, NodeTable},
};
pub type Variable = Content;
#[derive(Debug, Clone)]
pub struct EnvVar {
variables: HashMap<String, Variable>,
}
impl EnvVar {
pub fn new(node_table: NodeTable) -> Self {
let mut env = Self {
variables: HashMap::default(),
};
env.set(NODE_TABLE_STR, node_table);
env
}
#[allow(unused)]
pub fn set<H: Send + Sync + 'static>(&mut self, name: &str, var: H) {
let mut v = Variable::new(var);
self.variables.insert(name.to_owned(), v);
}
pub fn get<H: Send + Sync + Clone + 'static>(&self, name: &str) -> Option<H> {
self.get_ref(name).cloned()
}
pub fn get_ref<H: Send + Sync + 'static>(&self, name: &str) -> Option<&H> {
if let Some(content) = self.variables.get(name) {
content.get()
} else {
None
}
}
}