Allow Result aliases to be used with two type parameters

master
Jonas Platte 2021-04-01 19:35:09 +02:00
parent ff683602f2
commit 79eb07f717
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
5 changed files with 7 additions and 10 deletions

View File

@ -23,7 +23,7 @@ use thiserror::Error;
use matrix_sdk_crypto::{CryptoStoreError, MegolmError, OlmError}; use matrix_sdk_crypto::{CryptoStoreError, MegolmError, OlmError};
/// Result type of the rust-sdk. /// Result type of the rust-sdk.
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T, E = Error> = std::result::Result<T, E>;
/// Internal representation of errors. /// Internal representation of errors.
#[derive(Error, Debug)] #[derive(Error, Debug)]

View File

@ -76,7 +76,7 @@ pub enum StoreError {
} }
/// A `StateStore` specific result type. /// A `StateStore` specific result type.
pub type Result<T> = std::result::Result<T, StoreError>; pub type Result<T, E = StoreError> = std::result::Result<T, E>;
/// An abstract state store trait that can be used to implement different stores /// An abstract state store trait that can be used to implement different stores
/// for the SDK. /// for the SDK.

View File

@ -249,10 +249,7 @@ impl SledStore {
SledStore::open_helper(db, Some(path), None) SledStore::open_helper(db, Some(path), None)
} }
fn serialize_event( fn serialize_event(&self, event: &impl Serialize) -> Result<Vec<u8>, SerializationError> {
&self,
event: &impl Serialize,
) -> std::result::Result<Vec<u8>, SerializationError> {
if let Some(key) = &*self.store_key { if let Some(key) = &*self.store_key {
let encrypted = key.encrypt(event)?; let encrypted = key.encrypt(event)?;
Ok(serde_json::to_vec(&encrypted)?) Ok(serde_json::to_vec(&encrypted)?)
@ -264,7 +261,7 @@ impl SledStore {
fn deserialize_event<T: for<'b> Deserialize<'b>>( fn deserialize_event<T: for<'b> Deserialize<'b>>(
&self, &self,
event: &[u8], event: &[u8],
) -> std::result::Result<T, SerializationError> { ) -> Result<T, SerializationError> {
if let Some(key) = &*self.store_key { if let Some(key) = &*self.store_key {
let encrypted: EncryptedEvent = serde_json::from_slice(&event)?; let encrypted: EncryptedEvent = serde_json::from_slice(&event)?;
Ok(key.decrypt(encrypted)?) Ok(key.decrypt(encrypted)?)
@ -297,7 +294,7 @@ impl SledStore {
pub async fn save_changes(&self, changes: &StateChanges) -> Result<()> { pub async fn save_changes(&self, changes: &StateChanges) -> Result<()> {
let now = SystemTime::now(); let now = SystemTime::now();
let ret: std::result::Result<(), TransactionError<SerializationError>> = ( let ret: Result<(), TransactionError<SerializationError>> = (
&self.session, &self.session,
&self.account_data, &self.account_data,
&self.members, &self.members,

View File

@ -82,7 +82,7 @@ use crate::{
}; };
/// A `CryptoStore` specific result type. /// A `CryptoStore` specific result type.
pub type Result<T> = std::result::Result<T, CryptoStoreError>; pub type Result<T, E = CryptoStoreError> = std::result::Result<T, E>;
/// A wrapper for our CryptoStore trait object. /// A wrapper for our CryptoStore trait object.
/// ///

View File

@ -333,7 +333,7 @@ impl SledStore {
let identity_changes = changes.identities; let identity_changes = changes.identities;
let olm_hashes = changes.message_hashes; let olm_hashes = changes.message_hashes;
let ret: std::result::Result<(), TransactionError<serde_json::Error>> = ( let ret: Result<(), TransactionError<serde_json::Error>> = (
&self.account, &self.account,
&self.private_identity, &self.private_identity,
&self.devices, &self.devices,