From 385df955c3b54cfd7ac471bef2984bb08bd65ab3 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 4 Apr 2025 12:19:54 +0200 Subject: [PATCH] refactor(sdk): Reduce the size of `Error::SlidingSync`. This patch boxes the error in `Error::SlidingSync` to reduce the size of this variant (from 72 bytes to 16 bytes). --- crates/matrix-sdk/src/error.rs | 10 ++++++++-- crates/matrix-sdk/src/sliding_sync/builder.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk/src/error.rs b/crates/matrix-sdk/src/error.rs index 79c45fcfd..6abd0c112 100644 --- a/crates/matrix-sdk/src/error.rs +++ b/crates/matrix-sdk/src/error.rs @@ -47,7 +47,7 @@ use url::ParseError as UrlParseError; use crate::{ event_cache::EventCacheError, media::MediaError, room::reply::ReplyError, - store_locks::LockStoreError, + sliding_sync::Error as SlidingSyncError, store_locks::LockStoreError, }; /// Result type of the matrix-sdk. @@ -342,7 +342,7 @@ pub enum Error { /// An error occurred within sliding-sync #[error(transparent)] - SlidingSync(#[from] crate::sliding_sync::Error), + SlidingSync(Box), /// Attempted to call a method on a room that requires the user to have a /// specific membership state in the room, but the membership state is @@ -477,6 +477,12 @@ impl From for Error { } } +impl From for Error { + fn from(error: SlidingSyncError) -> Self { + Error::SlidingSync(Box::new(error)) + } +} + /// Error for the room key importing functionality. #[cfg(feature = "e2e-encryption")] #[derive(Error, Debug)] diff --git a/crates/matrix-sdk/src/sliding_sync/builder.rs b/crates/matrix-sdk/src/sliding_sync/builder.rs index 7c40b540b..42434a430 100644 --- a/crates/matrix-sdk/src/sliding_sync/builder.rs +++ b/crates/matrix-sdk/src/sliding_sync/builder.rs @@ -232,7 +232,7 @@ impl SlidingSyncBuilder { let version = self.version.unwrap_or_else(|| client.sliding_sync_version()); if matches!(version, Version::None) { - return Err(crate::error::Error::SlidingSync(Error::VersionIsMissing)); + return Err(crate::error::Error::SlidingSync(Box::new(Error::VersionIsMissing))); } let (internal_channel_sender, _internal_channel_receiver) = channel(8);