mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-17 21:20:06 -04:00
sdk-base: Add constructors with stores for StoreConfig
This commit is contained in:
@@ -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<dyn StateStore>) -> 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<dyn StateStore>,
|
||||
crypto_store: Box<dyn CryptoStore>,
|
||||
) -> 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.
|
||||
|
||||
@@ -45,14 +45,12 @@ async fn make_store_config(
|
||||
name: impl Into<String>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<StoreConfig, anyhow::Error> {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -35,13 +35,10 @@ pub fn make_store_config(
|
||||
path: impl AsRef<Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<StoreConfig, anyhow::Error> {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user