wacore/sync_marker.rs
1//! Conditional `Send + Sync` bound.
2//!
3//! Native builds drive the client across multi-threaded receive lanes, so any
4//! trait object stored on it must be `Send + Sync`. wasm32 is single-threaded
5//! and its callbacks may hold `!Send` JS handles (see
6//! [`crate::msg_secret::OriginalMessageResolver`]), so the bound is dropped
7//! there. The blanket impls keep this transparent: on native every
8//! `Send + Sync` type already satisfies it, on wasm every type does.
9
10#[cfg(not(target_arch = "wasm32"))]
11pub trait MaybeSendSync: Send + Sync {}
12#[cfg(not(target_arch = "wasm32"))]
13impl<T: Send + Sync + ?Sized> MaybeSendSync for T {}
14
15#[cfg(target_arch = "wasm32")]
16pub trait MaybeSendSync {}
17#[cfg(target_arch = "wasm32")]
18impl<T: ?Sized> MaybeSendSync for T {}
19
20/// `Send`-only variant for values that cross task boundaries but are never
21/// shared by reference (closures, futures). Same wasm rationale as
22/// [`MaybeSendSync`].
23#[cfg(not(target_arch = "wasm32"))]
24pub trait MaybeSend: Send {}
25#[cfg(not(target_arch = "wasm32"))]
26impl<T: Send + ?Sized> MaybeSend for T {}
27
28#[cfg(target_arch = "wasm32")]
29pub trait MaybeSend {}
30#[cfg(target_arch = "wasm32")]
31impl<T: ?Sized> MaybeSend for T {}