Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <[email protected]>
  • Loading branch information
rylev committed Jul 30, 2024
1 parent c4d6f45 commit afebc8e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/factor-key-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct KeyValueFactor {
impl KeyValueFactor {
/// Create a new KeyValueFactor.
///
/// The `default_label_resolver` is used to resolver store managers for labels that
/// The `default_label_resolver` is used to resolve store managers for labels that
/// are not defined in the runtime configuration.
pub fn new(default_label_resolver: impl DefaultLabelResolver + 'static) -> Self {
Self {
Expand Down
9 changes: 8 additions & 1 deletion crates/factor-key-value/src/runtime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ use spin_key_value::StoreManager;
#[derive(Default)]
pub struct RuntimeConfig {
/// Map of store names to store managers.
pub store_managers: HashMap<String, Arc<dyn StoreManager>>,
store_managers: HashMap<String, Arc<dyn StoreManager>>,
}

impl RuntimeConfig {
/// Adds a store manager for the store with the given label to the runtime configuration.
pub fn add_store_manager(&mut self, label: String, store_manager: Arc<dyn StoreManager>) {
self.store_managers.insert(label, store_manager);
}
}

impl IntoIterator for RuntimeConfig {
Expand Down
16 changes: 6 additions & 10 deletions crates/factor-key-value/src/runtime_config/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ impl RuntimeConfigResolver {
let Some(table) = table.as_ref().and_then(|t| t.get("key_value_store")) else {
return Ok(None);
};
let mut store_configs = HashMap::new();
for (label, config) in table
.as_table()
.context("expected a 'key_value_store' to contain toml table")?
{
let config: StoreConfig = config.clone().try_into()?;
let table: HashMap<String, StoreConfig> = table.clone().try_into()?;

let mut runtime_config = RuntimeConfig::default();
for (label, config) in table {
let store_manager = self.store_manager_from_config(config)?;
store_configs.insert(label.clone(), store_manager);
runtime_config.add_store_manager(label.clone(), store_manager);
}
Ok(Some(RuntimeConfig {
store_managers: store_configs,
}))
Ok(Some(runtime_config))
}

/// Given a [`StoreConfig`], returns a store manager.
Expand Down

0 comments on commit afebc8e

Please sign in to comment.