use std::{ collections::BTreeMap, sync::{Arc, RwLock}, }; use crate::{error::RwLockPoisonError, Value}; pub struct Context { inner: Arc>>, } impl Context { pub fn new() -> Self { Self { inner: Arc::new(RwLock::new(BTreeMap::new())), } } pub fn with_values(values: BTreeMap) -> Self { Self { inner: Arc::new(RwLock::new(values)), } } pub fn get(&self, key: &str) -> Result, RwLockPoisonError> { let value = self.inner.read()?.get(key).cloned(); Ok(value) } pub fn set(&self, key: String, value: Value) -> Result<(), RwLockPoisonError> { self.inner.write()?.insert(key, value); Ok(()) } }