use parking_lot::RwLock;
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Clone)]
pub struct ResourceDictionary {
inner: Arc<RwLock<HashMap<String, ResourceValue>>>,
}
#[derive(Clone)]
pub enum ResourceValue {
String(String),
Integer(i32),
Float(f64),
Boolean(bool),
}
impl ResourceDictionary {
pub fn new() -> Self {
ResourceDictionary {
inner: Arc::new(RwLock::new(HashMap::new())),
}
}
pub fn insert(&self, key: impl Into<String>, value: ResourceValue) {
self.inner.write().insert(key.into(), value);
}
pub fn get(&self, key: &str) -> Option<ResourceValue> {
self.inner.read().get(key).cloned()
}
pub fn remove(&self, key: &str) -> Option<ResourceValue> {
self.inner.write().remove(key)
}
pub fn clear(&self) {
self.inner.write().clear();
}
pub fn contains_key(&self, key: &str) -> bool {
self.inner.read().contains_key(key)
}
}
impl Default for ResourceDictionary {
fn default() -> Self {
Self::new()
}
}