Skip to main content

webtrans_trait/
bounds.rs

1//! Conditional Send/Sync bounds for native and WASM.
2//!
3//! WASM targets generally don't support Send/Sync in the same way as native.
4//! These marker traits let us write one set of trait bounds across targets.
5
6/// A trait that is Send on native targets and a no-op on WASM.
7#[cfg(not(target_family = "wasm"))]
8pub trait MaybeSend: Send {}
9
10/// A trait that is Sync on native targets and a no-op on WASM.
11#[cfg(not(target_family = "wasm"))]
12pub trait MaybeSync: Sync {}
13
14#[cfg(not(target_family = "wasm"))]
15impl<T: Send> MaybeSend for T {}
16
17#[cfg(not(target_family = "wasm"))]
18impl<T: Sync> MaybeSync for T {}
19
20/// A trait that is Send on native targets and a no-op on WASM.
21#[cfg(target_family = "wasm")]
22pub trait MaybeSend {}
23
24/// A trait that is Sync on native targets and a no-op on WASM.
25#[cfg(target_family = "wasm")]
26pub trait MaybeSync {}
27
28#[cfg(target_family = "wasm")]
29impl<T> MaybeSend for T {}
30
31#[cfg(target_family = "wasm")]
32impl<T> MaybeSync for T {}