From 6c40ab513574b1e6dbd82e60cd02913a571b98c8 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 4 Dec 2024 13:47:06 +0800 Subject: [PATCH] Remove Send requirement for wasm32. --- .../protocol/src/integration/linked_account.rs | 18 ++++++++++++------ .../protocol/src/integration/local_client.rs | 3 ++- crates/protocol/src/local_transport.rs | 3 ++- crates/protocol/src/sync/auto_merge.rs | 3 ++- crates/protocol/src/sync/local_account.rs | 9 ++++++--- crates/protocol/src/sync/primitives.rs | 9 ++++++--- crates/protocol/src/sync/remote.rs | 3 ++- crates/protocol/src/traits.rs | 6 ++++-- crates/sdk/src/account/account.rs | 9 ++++++--- crates/sdk/src/storage/mod.rs | 3 ++- 10 files changed, 44 insertions(+), 22 deletions(-) diff --git a/crates/protocol/src/integration/linked_account.rs b/crates/protocol/src/integration/linked_account.rs index 5d7b3d881d..4bf776b989 100644 --- a/crates/protocol/src/integration/linked_account.rs +++ b/crates/protocol/src/integration/linked_account.rs @@ -109,7 +109,8 @@ impl LinkedAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Account for LinkedAccount { type Error = Error; type NetworkResult = RemoteResult; @@ -1027,7 +1028,8 @@ impl Account for LinkedAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl StorageEventLogs for LinkedAccount { async fn identity_log( &self, @@ -1075,7 +1077,8 @@ impl StorageEventLogs for LinkedAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl SyncStorage for LinkedAccount { fn is_client_storage(&self) -> bool { true @@ -1087,7 +1090,8 @@ impl SyncStorage for LinkedAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl RemoteSyncHandler for LinkedAccount { type Client = LocalClient; type Account = LocalAccount; @@ -1124,10 +1128,12 @@ impl RemoteSyncHandler for LinkedAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl AutoMerge for LinkedAccount {} -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl RemoteSync for LinkedAccount { type Error = Error; diff --git a/crates/protocol/src/integration/local_client.rs b/crates/protocol/src/integration/local_client.rs index 10cd5a8f10..10abe9c097 100644 --- a/crates/protocol/src/integration/local_client.rs +++ b/crates/protocol/src/integration/local_client.rs @@ -111,7 +111,8 @@ impl LocalClient { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl SyncClient for LocalClient { type Error = Error; diff --git a/crates/protocol/src/local_transport.rs b/crates/protocol/src/local_transport.rs index 8a89174f31..1850273c81 100644 --- a/crates/protocol/src/local_transport.rs +++ b/crates/protocol/src/local_transport.rs @@ -144,7 +144,8 @@ impl LocalResponse { } /// Generic local transport. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait LocalTransport { /// Send a request over the local transport. async fn call(&mut self, request: LocalRequest) -> Result; diff --git a/crates/protocol/src/sync/auto_merge.rs b/crates/protocol/src/sync/auto_merge.rs index 4358f7bac5..7bd3b8e4c3 100644 --- a/crates/protocol/src/sync/auto_merge.rs +++ b/crates/protocol/src/sync/auto_merge.rs @@ -49,7 +49,8 @@ pub enum AutoMergeStatus { } /// Support for auto merge on sync. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait AutoMerge: RemoteSyncHandler { /// Execute the sync operation. /// diff --git a/crates/protocol/src/sync/local_account.rs b/crates/protocol/src/sync/local_account.rs index 707943fe9b..fab4a3b56c 100644 --- a/crates/protocol/src/sync/local_account.rs +++ b/crates/protocol/src/sync/local_account.rs @@ -30,7 +30,8 @@ use crate::sdk::events::{DeviceDiff, DeviceReducer}; #[cfg(feature = "files")] use crate::sdk::events::FileDiff; -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl ForceMerge for LocalAccount { async fn force_merge_identity( &mut self, @@ -161,7 +162,8 @@ impl ForceMerge for LocalAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Merge for LocalAccount { async fn merge_identity( &mut self, @@ -544,7 +546,8 @@ impl Merge for LocalAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl SyncStorage for LocalAccount { fn is_client_storage(&self) -> bool { true diff --git a/crates/protocol/src/sync/primitives.rs b/crates/protocol/src/sync/primitives.rs index c3eaefa92c..8d2b28d9d3 100644 --- a/crates/protocol/src/sync/primitives.rs +++ b/crates/protocol/src/sync/primitives.rs @@ -428,7 +428,8 @@ impl SyncComparison { } /// Storage implementations that can synchronize. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait SyncStorage: StorageEventLogs { /// Determine if this is client-side storage. fn is_client_storage(&self) -> bool; @@ -499,7 +500,8 @@ pub trait SyncStorage: StorageEventLogs { /// /// Use this when event logs have completely diverged /// and need to be rewritten. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait ForceMerge { /// Force merge changes to the identity folder. async fn force_merge_identity( @@ -540,7 +542,8 @@ pub trait ForceMerge { } /// Types that can merge diffs. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait Merge { /// Merge changes to the identity folder. async fn merge_identity( diff --git a/crates/protocol/src/sync/remote.rs b/crates/protocol/src/sync/remote.rs index ed564426fe..54e5bff8be 100644 --- a/crates/protocol/src/sync/remote.rs +++ b/crates/protocol/src/sync/remote.rs @@ -18,7 +18,8 @@ use super::ForceMerge; /// Trait for types that bridge between a remote data source /// and a local account. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait RemoteSyncHandler { /// Client used to fetch data from the data source. type Client: SyncClient + Send + Sync + 'static; diff --git a/crates/protocol/src/traits.rs b/crates/protocol/src/traits.rs index ba5fad2f60..faa77cdbf5 100644 --- a/crates/protocol/src/traits.rs +++ b/crates/protocol/src/traits.rs @@ -60,7 +60,8 @@ impl SyncResult { } /// Trait for types that can sync with a single remote. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait RemoteSync { /// Error type for remote sync. type Error: std::error::Error + std::fmt::Debug; @@ -152,7 +153,8 @@ pub trait AccountSync { } /// Client that can communicate with a remote data source. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait SyncClient { /// Error type for sync client. type Error: std::error::Error + std::fmt::Debug; diff --git a/crates/sdk/src/account/account.rs b/crates/sdk/src/account/account.rs index 40577b1634..b4d7c73e54 100644 --- a/crates/sdk/src/account/account.rs +++ b/crates/sdk/src/account/account.rs @@ -299,7 +299,8 @@ pub enum ContactImportProgress { } /// Trait for account implementations. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait Account { /// Errors for this account. type Error: std::error::Error + std::fmt::Debug + From; @@ -1653,7 +1654,8 @@ impl LocalAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl Account for LocalAccount { type Error = Error; type NetworkResult = (); @@ -3378,7 +3380,8 @@ impl Account for LocalAccount { } } -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl StorageEventLogs for LocalAccount { async fn identity_log(&self) -> Result>> { let storage = self.storage.as_ref().ok_or(Error::NoStorage)?; diff --git a/crates/sdk/src/storage/mod.rs b/crates/sdk/src/storage/mod.rs index 94fbc8f2ea..8293715e59 100644 --- a/crates/sdk/src/storage/mod.rs +++ b/crates/sdk/src/storage/mod.rs @@ -116,7 +116,8 @@ pub fn guess_mime(path: impl AsRef) -> Result { } /// References to the storage event logs. -#[async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait StorageEventLogs { /// Clone of the identity log. async fn identity_log(&self) -> Result>>;