From 6bed51f0161ebc7cd5b26781013c6e4cbd0f0f4e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 4 Aug 2022 13:03:07 +0200 Subject: [PATCH] refactor(indexeddb)!: Use &str for name in public API --- crates/matrix-sdk-indexeddb/src/crypto_store.rs | 8 ++++---- crates/matrix-sdk-indexeddb/src/lib.rs | 11 ++++------- crates/matrix-sdk/src/client/builder.rs | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store.rs b/crates/matrix-sdk-indexeddb/src/crypto_store.rs index daaf5a25f..c829a784e 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store.rs @@ -138,7 +138,7 @@ pub struct AccountInfo { impl IndexeddbCryptoStore { pub(crate) async fn open_with_store_cipher( - prefix: String, + prefix: &str, store_cipher: Option>, ) -> Result { let name = format!("{:0}::matrix-sdk-crypto", prefix); @@ -185,7 +185,7 @@ impl IndexeddbCryptoStore { /// Open a new `IndexeddbCryptoStore` with default name and no passphrase pub async fn open() -> Result { - IndexeddbCryptoStore::open_with_store_cipher("crypto".to_owned(), None).await + IndexeddbCryptoStore::open_with_store_cipher("crypto", None).await } fn encode_key(&self, table_name: &str, key: T) -> JsValue @@ -218,7 +218,7 @@ impl IndexeddbCryptoStore { } /// Open a new `IndexeddbCryptoStore` with given name and passphrase - pub async fn open_with_passphrase(prefix: String, passphrase: &str) -> Result { + pub async fn open_with_passphrase(prefix: &str, passphrase: &str) -> Result { let name = format!("{:0}::matrix-sdk-crypto-meta", prefix); let mut db_req: OpenDbRequest = IdbDatabase::open_f64(&name, 1.0)?; @@ -270,7 +270,7 @@ impl IndexeddbCryptoStore { } /// Open a new `IndexeddbCryptoStore` with given name and no passphrase - pub async fn open_with_name(name: String) -> Result { + pub async fn open_with_name(name: &str) -> Result { IndexeddbCryptoStore::open_with_store_cipher(name, None).await } diff --git a/crates/matrix-sdk-indexeddb/src/lib.rs b/crates/matrix-sdk-indexeddb/src/lib.rs index 1fcc05ee5..2232f8037 100644 --- a/crates/matrix-sdk-indexeddb/src/lib.rs +++ b/crates/matrix-sdk-indexeddb/src/lib.rs @@ -19,12 +19,11 @@ pub use state_store::{ /// same name and passphrase. #[cfg(feature = "e2e-encryption")] async fn open_stores_with_name( - name: impl Into, + name: &str, passphrase: Option<&str>, ) -> Result<(IndexeddbStateStore, IndexeddbCryptoStore), OpenStoreError> { - let name = name.into(); let mut builder = IndexeddbStateStore::builder(); - builder.name(name.clone()); + builder.name(name.to_owned()); if let Some(passphrase) = passphrase { builder.passphrase(passphrase.to_owned()); @@ -42,13 +41,11 @@ async fn open_stores_with_name( /// that uses the given name and passphrase. If `encryption` is enabled, a /// [`IndexeddbCryptoStore`] with the same parameters is also opened. pub async fn make_store_config( - name: impl Into, + name: &str, passphrase: Option<&str>, ) -> Result { #[cfg(target_arch = "wasm32")] { - let name = name.into(); - #[cfg(feature = "e2e-encryption")] { let (state_store, crypto_store) = open_stores_with_name(name, passphrase).await?; @@ -58,7 +55,7 @@ pub async fn make_store_config( #[cfg(not(feature = "e2e-encryption"))] { let mut builder = IndexeddbStateStore::builder(); - builder.name(name.clone()); + builder.name(name.to_owned()); if let Some(passphrase) = passphrase { builder.passphrase(passphrase.to_owned()); diff --git a/crates/matrix-sdk/src/client/builder.rs b/crates/matrix-sdk/src/client/builder.rs index 8d2350c9c..3b9987168 100644 --- a/crates/matrix-sdk/src/client/builder.rs +++ b/crates/matrix-sdk/src/client/builder.rs @@ -141,7 +141,7 @@ impl ClientBuilder { #[cfg(feature = "indexeddb")] pub async fn indexeddb_store( self, - name: impl Into, + name: &str, passphrase: Option<&str>, ) -> Result { let config = matrix_sdk_indexeddb::make_store_config(name, passphrase).await?;