launchdarkly_server_sdk/stores/
store_builders.rs1use super::store::{DataStore, InMemoryDataStore};
2use parking_lot::RwLock;
3use std::sync::Arc;
4use thiserror::Error;
5
6#[non_exhaustive]
7#[derive(Debug, Error)]
8pub enum BuildError {
9 #[error("data store factory failed to build: {0}")]
10 InvalidConfig(String),
11}
12
13pub trait DataStoreFactory {
15 fn build(&self) -> Result<Arc<RwLock<dyn DataStore>>, BuildError>;
16 fn to_owned(&self) -> Box<dyn DataStoreFactory>;
17}
18
19#[derive(Clone)]
23pub struct InMemoryDataStoreBuilder {}
24
25impl InMemoryDataStoreBuilder {
26 pub fn new() -> Self {
27 Self {}
28 }
29}
30
31impl DataStoreFactory for InMemoryDataStoreBuilder {
32 fn build(&self) -> Result<Arc<RwLock<dyn DataStore>>, BuildError> {
33 Ok(Arc::new(RwLock::new(InMemoryDataStore::new())))
34 }
35
36 fn to_owned(&self) -> Box<dyn DataStoreFactory> {
37 Box::new(self.clone())
38 }
39}