spin_factor_key_value/
runtime_config.rs

1pub mod spin;
2
3use std::{collections::HashMap, sync::Arc};
4
5use crate::StoreManager;
6
7/// Runtime configuration for all key value stores.
8#[derive(Default, Clone)]
9pub struct RuntimeConfig {
10    /// Map of store names to store managers.
11    store_managers: HashMap<String, Arc<dyn StoreManager>>,
12}
13
14impl RuntimeConfig {
15    /// Adds a store manager for the store with the given label to the runtime configuration.
16    ///
17    /// If a store manager already exists for the given label, it will be replaced.
18    pub fn add_store_manager(&mut self, label: String, store_manager: Arc<dyn StoreManager>) {
19        self.store_managers.insert(label, store_manager);
20    }
21
22    /// Returns whether a store manager exists for the store with the given label.
23    pub fn has_store_manager(&self, label: &str) -> bool {
24        self.store_managers.contains_key(label)
25    }
26
27    /// Returns the store manager for the store with the given label.
28    pub fn get_store_manager(&self, label: &str) -> Option<Arc<dyn StoreManager>> {
29        self.store_managers.get(label).cloned()
30    }
31}
32
33impl IntoIterator for RuntimeConfig {
34    type Item = (String, Arc<dyn StoreManager>);
35    type IntoIter = std::collections::hash_map::IntoIter<String, Arc<dyn StoreManager>>;
36
37    fn into_iter(self) -> Self::IntoIter {
38        self.store_managers.into_iter()
39    }
40}