wnfs_common/utils/
send_sync_poly.rs1#[cfg(not(target_arch = "wasm32"))]
4pub type Arc<T> = std::sync::Arc<T>;
5
6#[cfg(target_arch = "wasm32")]
9pub type Arc<T> = std::rc::Rc<T>;
10
11#[cfg(not(target_arch = "wasm32"))]
14pub type BoxFuture<'a, T> = futures::future::BoxFuture<'a, T>;
15
16#[cfg(target_arch = "wasm32")]
19pub type BoxFuture<'a, T> = futures::future::LocalBoxFuture<'a, T>;
20
21#[cfg(not(target_arch = "wasm32"))]
24pub type BoxStream<'a, T> = futures::stream::BoxStream<'a, T>;
25
26#[cfg(target_arch = "wasm32")]
29pub type BoxStream<'a, T> = futures::stream::LocalBoxStream<'a, T>;
30
31#[cfg(not(target_arch = "wasm32"))]
34pub trait CondSend: Send {}
35
36#[cfg(target_arch = "wasm32")]
39pub trait CondSend {}
40
41#[cfg(not(target_arch = "wasm32"))]
42impl<S> CondSend for S where S: Send {}
43
44#[cfg(target_arch = "wasm32")]
45impl<S> CondSend for S {}
46
47#[cfg(not(target_arch = "wasm32"))]
50pub trait CondSync: Send + Sync {}
51
52#[cfg(target_arch = "wasm32")]
55pub trait CondSync {}
56
57#[cfg(not(target_arch = "wasm32"))]
58impl<S> CondSync for S where S: Send + Sync {}
59
60#[cfg(target_arch = "wasm32")]
61impl<S> CondSync for S {}
62
63#[cfg(not(target_arch = "wasm32"))]
64pub fn boxed_fut<'a, T>(
65 fut: impl futures::future::Future<Output = T> + Sized + CondSend + 'a,
66) -> BoxFuture<'a, T> {
67 futures::future::FutureExt::boxed(fut)
68}
69
70#[cfg(target_arch = "wasm32")]
71pub fn boxed_fut<'a, T>(
72 fut: impl futures::future::Future<Output = T> + Sized + CondSend + 'a,
73) -> BoxFuture<'a, T> {
74 futures::future::FutureExt::boxed_local(fut)
75}
76
77#[cfg(not(target_arch = "wasm32"))]
78pub fn boxed_stream<'a, T>(
79 stream: impl futures::stream::Stream<Item = T> + Sized + CondSend + 'a,
80) -> BoxStream<'a, T> {
81 futures::stream::StreamExt::boxed(stream)
82}
83
84#[cfg(target_arch = "wasm32")]
85pub fn boxed_stream<'a, T>(
86 stream: impl futures::stream::Stream<Item = T> + Sized + CondSend + 'a,
87) -> BoxStream<'a, T> {
88 futures::stream::StreamExt::boxed_local(stream)
89}