use StorageConfig instead of ReplicaConfig

This commit is contained in:
Dustin J. Mitchell 2021-01-10 21:48:28 -05:00
parent b004b6cb93
commit 02d9c577ab
6 changed files with 30 additions and 21 deletions

View file

@ -0,0 +1,23 @@
use super::{InMemoryStorage, KVStorage, Storage};
use failure::Fallible;
use std::path::PathBuf;
/// The configuration required for a replica's storage.
pub enum StorageConfig {
/// Store the data on disk. This is the common choice.
OnDisk {
/// Path containing the task DB.
taskdb_dir: PathBuf,
},
/// Store the data in memory. This is only useful for testing.
InMemory,
}
impl StorageConfig {
pub fn into_storage(self) -> Fallible<Box<dyn Storage>> {
Ok(match self {
StorageConfig::OnDisk { taskdb_dir } => Box::new(KVStorage::new(taskdb_dir)?),
StorageConfig::InMemory => Box::new(InMemoryStorage::new()),
})
}
}

View file

@ -2,11 +2,13 @@ use failure::Fallible;
use std::collections::HashMap;
use uuid::Uuid;
mod config;
mod inmemory;
mod kv;
mod operation;
pub use self::kv::KVStorage;
pub use config::StorageConfig;
pub use inmemory::InMemoryStorage;
pub use operation::Operation;