diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index 7fb043cf6..93d3bbca1 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -641,6 +641,24 @@ impl StoreConfig { Default::default() } + /// Create a new store config wrapping the given state store + pub fn new_with_state_store(state_store: Box) -> Self { + StoreConfig { + state_store: Some(state_store), + #[cfg(feature = "encryption")] + crypto_store: Default::default(), + } + } + + /// Create a new store config wrapping the given state and crypto store + #[cfg(feature = "encryption")] + pub fn new_with_state_and_crypto_store( + state_store: Box, + crypto_store: Box, + ) -> Self { + StoreConfig { state_store: Some(state_store), crypto_store: Some(crypto_store) } + } + /// Set a custom implementation of a `CryptoStore`. /// /// The crypto store must be opened before being set. diff --git a/crates/matrix-sdk-indexeddb/src/lib.rs b/crates/matrix-sdk-indexeddb/src/lib.rs index ac98ad047..1f425b94e 100644 --- a/crates/matrix-sdk-indexeddb/src/lib.rs +++ b/crates/matrix-sdk-indexeddb/src/lib.rs @@ -45,14 +45,12 @@ async fn make_store_config( name: impl Into, passphrase: Option<&str>, ) -> Result { - let mut config = StoreConfig::new(); let name = name.into(); #[cfg(feature = "encryption")] { let (state_store, crypto_store) = open_stores_with_name(name, passphrase).await?; - config = config.state_store(state_store); - config = config.crypto_store(crypto_store); + Ok(StoreConfig::new_with_state_and_crypto_store(state_store, crypto_store)) } #[cfg(not(feature = "encryption"))] @@ -63,8 +61,6 @@ async fn make_store_config( StateStore::open_with_name(name).await? }; - config = config.state_store(Box::new(state_store)); + Ok(StoreConfig::new_with_state_store(Box::new(state_store))) } - - Ok(config) } diff --git a/crates/matrix-sdk-sled/src/lib.rs b/crates/matrix-sdk-sled/src/lib.rs index ea02b950b..3647a4e91 100644 --- a/crates/matrix-sdk-sled/src/lib.rs +++ b/crates/matrix-sdk-sled/src/lib.rs @@ -35,13 +35,10 @@ pub fn make_store_config( path: impl AsRef, passphrase: Option<&str>, ) -> Result { - let mut config = StoreConfig::new(); - #[cfg(feature = "encryption")] { let (state_store, crypto_store) = open_stores_with_path(path, passphrase)?; - config = config.state_store(state_store); - config = config.crypto_store(crypto_store); + Ok(StoreConfig::new_with_state_and_crypto_store(state_store, crypto_store)) } #[cfg(not(feature = "encryption"))] @@ -52,8 +49,6 @@ pub fn make_store_config( StateStore::open_with_path(path)? }; - config = config.state_store(Box::new(state_store)); + Ok(StoreConfig::new_with_state_store(Box::new(state_store))) } - - Ok(config) } diff --git a/crates/matrix-sdk/src/config/client.rs b/crates/matrix-sdk/src/config/client.rs index 3a554f546..7340aabef 100644 --- a/crates/matrix-sdk/src/config/client.rs +++ b/crates/matrix-sdk/src/config/client.rs @@ -121,7 +121,7 @@ impl ClientConfig { /// # let custom_state_store = Box::new(MemoryStore::new()); /// use matrix_sdk::{Client, config::{ClientConfig, StoreConfig}}; /// - /// let store_config = StoreConfig::new().state_store(custom_state_store); + /// let store_config = StoreConfig::new_with_state_store(custom_state_store); /// let client_config = ClientConfig::with_store_config(store_config) /// .use_discovery_response(); ///