rig/
wasm_compat.rs

1use std::pin::Pin;
2
3#[cfg(not(target_arch = "wasm32"))]
4pub trait WasmCompatSend: Send {}
5#[cfg(target_arch = "wasm32")]
6pub trait WasmCompatSend {}
7
8#[cfg(not(target_arch = "wasm32"))]
9impl<T> WasmCompatSend for T where T: Send {}
10#[cfg(target_arch = "wasm32")]
11impl<T> WasmCompatSend for T {}
12
13#[cfg(not(target_arch = "wasm32"))]
14pub trait WasmCompatSync: Sync {}
15#[cfg(target_arch = "wasm32")]
16pub trait WasmCompatSync {}
17
18#[cfg(not(target_arch = "wasm32"))]
19impl<T> WasmCompatSync for T where T: Sync {}
20#[cfg(target_arch = "wasm32")]
21impl<T> WasmCompatSync for T {}
22
23#[cfg(not(target_family = "wasm"))]
24pub type WasmBoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
25
26#[cfg(target_family = "wasm")]
27pub type WasmBoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
28
29#[macro_export]
30macro_rules! if_wasm {
31    ($($tokens:tt)*) => {
32        #[cfg(target_arch = "wasm32")]
33        $($tokens)*
34
35    };
36}
37
38#[macro_export]
39macro_rules! if_not_wasm {
40    ($($tokens:tt)*) => {
41        #[cfg(not(target_arch = "wasm32"))]
42        $($tokens)*
43
44    };
45}