use crate::{Options, OptionsCache, OptionsFactory, OptionsMonitorCache, OptionsSnapshot, Ref, Value};
pub struct OptionsManager<T: Value> {
factory: Ref<dyn OptionsFactory<T>>,
cache: OptionsCache<T>,
}
impl<T: Value> OptionsManager<T> {
#[inline]
pub fn new(factory: Ref<dyn OptionsFactory<T>>) -> Self {
Self {
factory,
cache: Default::default(),
}
}
}
impl<T: Value> Options<T> for OptionsManager<T> {
#[inline]
fn value(&self) -> Ref<T> {
self.get(None)
}
}
impl<T: Value> OptionsSnapshot<T> for OptionsManager<T> {
#[inline]
fn get(&self, name: Option<&str>) -> Ref<T> {
self.cache.get_or_add(name, &|n| self.factory.create(n).unwrap())
}
}