Skip to main content

dptree/
send.rs

1//! Conditional `Send`/`Sync` helpers for wasm32 target.
2
3use std::future::Future;
4use std::pin::Pin;
5
6/// `Send` on native targets; no bound on `wasm32`.
7#[cfg(not(target_arch = "wasm32"))]
8pub trait MaybeSend: Send {}
9#[cfg(not(target_arch = "wasm32"))]
10impl<T: Send + ?Sized> MaybeSend for T {}
11
12/// `Send` on native targets; no bound on `wasm32`.
13#[cfg(target_arch = "wasm32")]
14pub trait MaybeSend {}
15#[cfg(target_arch = "wasm32")]
16impl<T: ?Sized> MaybeSend for T {}
17
18/// `Sync` on native targets; no bound on `wasm32`.
19#[cfg(not(target_arch = "wasm32"))]
20pub trait MaybeSync: Sync {}
21#[cfg(not(target_arch = "wasm32"))]
22impl<T: Sync + ?Sized> MaybeSync for T {}
23
24/// `Sync` on native targets; no bound on `wasm32`.
25#[cfg(target_arch = "wasm32")]
26pub trait MaybeSync {}
27#[cfg(target_arch = "wasm32")]
28impl<T: ?Sized> MaybeSync for T {}
29
30/// A boxed future that is `Send` on native targets and not required to be `Send`
31/// on `wasm32`.
32#[cfg(not(target_arch = "wasm32"))]
33pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
34#[cfg(target_arch = "wasm32")]
35pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;