use crate::store::{Marshaler, StoreId};
use std::collections::HashMap;
use std::path::Path;
pub(crate) struct PathTable {
pub(crate) default: Box<Path>,
pub(crate) table: HashMap<StoreId, Box<Path>>,
}
impl PathTable {
pub fn get(&self, store_id: &StoreId) -> &Path {
self
.table
.get(store_id)
.map(AsRef::as_ref)
.unwrap_or_else(|| self.default.as_ref())
}
}
pub(crate) struct MarshalerTable {
pub(crate) default: Box<dyn Marshaler>,
pub(crate) table: HashMap<StoreId, Box<dyn Marshaler>>,
}
impl MarshalerTable {
pub fn get(&self, store_id: &StoreId) -> &dyn Marshaler {
self
.table
.get(store_id)
.map(AsRef::as_ref)
.unwrap_or_else(|| self.default.as_ref())
}
}