kithara_platform/system/support/maybe_send.rs
1pub use crate::common::maybe_send::WasmSend;
2
3pub trait MaybeSend: Send {}
4impl<T: Send> MaybeSend for T {}
5
6pub trait MaybeSync: Sync {}
7impl<T: Sync> MaybeSync for T {}
8
9/// Trait alias for `Future + MaybeSend`.
10///
11/// On native: `Future + Send` - allows `tokio::spawn`.
12/// On WASM: just `Future` - no `Send` requirement.
13///
14/// Use in return-position impl trait in trait methods:
15/// ```ignore
16/// fn poll_demand(&mut self) -> impl MaybeSendFuture<Output = Option<Plan>>;
17/// ```
18pub trait MaybeSendFuture: Future + Send {}
19impl<T: Future + Send> MaybeSendFuture for T {}
20
21/// Boxed future that is `Send` on native, unrestricted on WASM.
22///
23/// Use as return type in trait methods to make the returned future
24/// `Send`-compatible on native (enabling `tokio::spawn`) while keeping
25/// WASM compatibility.
26///
27/// ```ignore
28/// fn plan(&mut self) -> BoxFuture<'_, PlanOutcome<Self::Plan>>;
29/// ```
30pub type BoxFuture<'a, T> = std::pin::Pin<Box<dyn Future<Output = T> + Send + 'a>>;