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