From 0701561e45c07461de2452cdac7b3a7f33391504 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 8 Aug 2022 17:09:09 +0200 Subject: [PATCH] feat(common): Add SendOutsideWasm, SyncOutsideWasm --- crates/matrix-sdk-common/src/lib.rs | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/crates/matrix-sdk-common/src/lib.rs b/crates/matrix-sdk-common/src/lib.rs index 0f5213499..687e0ee13 100644 --- a/crates/matrix-sdk-common/src/lib.rs +++ b/crates/matrix-sdk-common/src/lib.rs @@ -8,18 +8,36 @@ pub mod executor; pub mod locks; pub mod timeout; -/// Super trait that is used for our store traits, this trait will differ if -/// it's used on WASM. WASM targets will not require `Send` and `Sync` to have -/// implemented, while other targets will. +/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on +/// wasm. #[cfg(not(target_arch = "wasm32"))] -pub trait AsyncTraitDeps: std::fmt::Debug + Send + Sync {} +pub trait SendOutsideWasm: Send {} #[cfg(not(target_arch = "wasm32"))] -impl AsyncTraitDeps for T {} +impl SendOutsideWasm for T {} + +/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on +/// wasm. +#[cfg(target_arch = "wasm32")] +pub trait SendOutsideWasm {} +#[cfg(target_arch = "wasm32")] +impl SendOutsideWasm for T {} + +/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on +/// wasm. +#[cfg(not(target_arch = "wasm32"))] +pub trait SyncOutsideWasm: Sync {} +#[cfg(not(target_arch = "wasm32"))] +impl SyncOutsideWasm for T {} + +/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on +/// wasm. +#[cfg(target_arch = "wasm32")] +pub trait SyncOutsideWasm {} +#[cfg(target_arch = "wasm32")] +impl SyncOutsideWasm for T {} /// Super trait that is used for our store traits, this trait will differ if /// it's used on WASM. WASM targets will not require `Send` and `Sync` to have /// implemented, while other targets will. -#[cfg(target_arch = "wasm32")] -pub trait AsyncTraitDeps: std::fmt::Debug {} -#[cfg(target_arch = "wasm32")] -impl AsyncTraitDeps for T {} +pub trait AsyncTraitDeps: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm {} +impl AsyncTraitDeps for T {}