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