Skip to content

Commit

Permalink
Remove Send requirement for wasm32.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Dec 4, 2024
1 parent 6726cc6 commit 6c40ab5
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 22 deletions.
18 changes: 12 additions & 6 deletions crates/protocol/src/integration/linked_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Error>;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion crates/protocol/src/integration/local_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion crates/protocol/src/local_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocalResponse>;
Expand Down
3 changes: 2 additions & 1 deletion crates/protocol/src/sync/auto_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
9 changes: 6 additions & 3 deletions crates/protocol/src/sync/local_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions crates/protocol/src/sync/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion crates/protocol/src/sync/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions crates/protocol/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ impl<E> SyncResult<E> {
}

/// 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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions crates/sdk/src/account/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Error>;
Expand Down Expand Up @@ -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 = ();
Expand Down Expand Up @@ -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<Arc<RwLock<FolderEventLog>>> {
let storage = self.storage.as_ref().ok_or(Error::NoStorage)?;
Expand Down
3 changes: 2 additions & 1 deletion crates/sdk/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ pub fn guess_mime(path: impl AsRef<Path>) -> Result<String> {
}

/// 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<Arc<RwLock<FolderEventLog>>>;
Expand Down

0 comments on commit 6c40ab5

Please sign in to comment.