rig/
wasm_compat.rs

1use bytes::Bytes;
2use std::pin::Pin;
3
4use futures::Stream;
5
6#[cfg(not(target_arch = "wasm32"))]
7pub trait WasmCompatSend: Send {}
8#[cfg(target_arch = "wasm32")]
9pub trait WasmCompatSend {}
10
11#[cfg(not(target_arch = "wasm32"))]
12impl<T> WasmCompatSend for T where T: Send {}
13#[cfg(target_arch = "wasm32")]
14impl<T> WasmCompatSend for T {}
15
16#[cfg(not(target_arch = "wasm32"))]
17pub trait WasmCompatSendStream:
18    Stream<Item = Result<Bytes, crate::http_client::Error>> + Send
19{
20    type InnerItem: Send;
21}
22
23#[cfg(target_arch = "wasm32")]
24pub trait WasmCompatSendStream: Stream<Item = Result<Bytes, crate::http_client::Error>> {
25    type InnerItem;
26}
27
28#[cfg(not(target_arch = "wasm32"))]
29impl<T> WasmCompatSendStream for T
30where
31    T: Stream<Item = Result<Bytes, crate::http_client::Error>> + Send,
32{
33    type InnerItem = Result<Bytes, crate::http_client::Error>;
34}
35
36#[cfg(target_arch = "wasm32")]
37impl<T> WasmCompatSendStream for T
38where
39    T: Stream<Item = Result<Bytes, crate::http_client::Error>>,
40{
41    type InnerItem = Result<Bytes, crate::http_client::Error>;
42}
43
44#[cfg(not(target_arch = "wasm32"))]
45pub trait WasmCompatSync: Sync {}
46#[cfg(target_arch = "wasm32")]
47pub trait WasmCompatSync {}
48
49#[cfg(not(target_arch = "wasm32"))]
50impl<T> WasmCompatSync for T where T: Sync {}
51#[cfg(target_arch = "wasm32")]
52impl<T> WasmCompatSync for T {}
53
54#[cfg(not(target_family = "wasm"))]
55pub type WasmBoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
56
57#[cfg(target_family = "wasm")]
58pub type WasmBoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
59
60#[macro_export]
61macro_rules! if_wasm {
62    ($($tokens:tt)*) => {
63        #[cfg(target_arch = "wasm32")]
64        $($tokens)*
65
66    };
67}
68
69#[macro_export]
70macro_rules! if_not_wasm {
71    ($($tokens:tt)*) => {
72        #[cfg(not(target_arch = "wasm32"))]
73        $($tokens)*
74
75    };
76}