mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-30 22:43:24 +02:00
use StorageConfig instead of ReplicaConfig
This commit is contained in:
parent
b004b6cb93
commit
02d9c577ab
6 changed files with 30 additions and 21 deletions
23
taskchampion/src/storage/config.rs
Normal file
23
taskchampion/src/storage/config.rs
Normal 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()),
|
||||
})
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue