web_transport_trait/
util.rs

1//! Utility traits for conditional Send/Sync bounds.
2//!
3//! These traits allow the same code to work on both native and WASM targets,
4//! where WASM doesn't support Send/Sync.
5
6/// A trait that is Send on native targets and empty on WASM.
7#[cfg(not(target_family = "wasm"))]
8pub trait MaybeSend: Send {}
9
10/// A trait that is Sync on native targets and empty 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 empty on WASM.
21#[cfg(target_family = "wasm")]
22pub trait MaybeSend {}
23
24/// A trait that is Sync on native targets and empty 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 {}