use std::collections::HashMap;
use std::sync::Mutex;
use crate::env::Environment;
pub struct BrowserEnvironment {
vars: Mutex<HashMap<String, String>>,
}
impl BrowserEnvironment {
pub fn new() -> Self {
Self {
vars: Mutex::new(HashMap::new()),
}
}
pub fn with_vars(vars: HashMap<String, String>) -> Self {
Self {
vars: Mutex::new(vars),
}
}
}
impl Default for BrowserEnvironment {
fn default() -> Self {
Self::new()
}
}
impl Environment for BrowserEnvironment {
fn get_var(&self, name: &str) -> Option<String> {
self.vars
.lock()
.expect("BrowserEnvironment mutex poisoned")
.get(name)
.cloned()
}
fn set_var(&self, name: &str, value: &str) {
self.vars
.lock()
.expect("BrowserEnvironment mutex poisoned")
.insert(name.to_string(), value.to_string());
}
fn remove_var(&self, name: &str) {
self.vars
.lock()
.expect("BrowserEnvironment mutex poisoned")
.remove(name);
}
}