use {
crate::LewpError,
std::{cell::RefCell, collections::HashMap, rc::Rc},
};
pub struct RuntimeInformation {
module_execution_count: RefCell<HashMap<String, u32>>,
previous_module_id: RefCell<Option<String>>,
}
impl RuntimeInformation {
pub fn new() -> Self {
Self {
module_execution_count: RefCell::new(HashMap::<String, u32>::new()),
previous_module_id: RefCell::new(None),
}
}
pub fn increase_execution_count(&self, id: &str) {
let execution_count = self.get_execution_count(id);
self.module_execution_count
.borrow_mut()
.insert(id.to_string(), execution_count + 1);
}
pub fn get_execution_count(&self, id: &str) -> u32 {
self.module_execution_count
.borrow()
.get(id)
.unwrap_or(&0)
.to_owned()
}
pub fn previous_module_id(&self) -> Option<String> {
self.previous_module_id.borrow().to_owned()
}
pub fn set_previous_module_id(&self, module_id: &str) {
*self.previous_module_id.borrow_mut() = Some(module_id.to_string());
}
}
impl Default for RuntimeInformation {
fn default() -> Self {
Self::new()
}
}