Expand description
Conditional Send bound for cross-platform compatibility.
On native targets, MaybeSend is equivalent to Send.
On wasm32, MaybeSend is auto-implemented for all types.
This allows traits to require Send on native (for multi-threaded runtimes)
while remaining compatible with wasm’s single-threaded execution model.
§Why This Exists
JavaScript interop types (like JsFuture, JsValue) are not Send
because wasm is single-threaded. But on native, tokio’s multi-threaded
runtime requires Send futures. MaybeSend bridges this gap:
ⓘ
// Instead of:
fn request() -> impl Future<Output = Response> + Send; // Won't compile on wasm!
// Use:
fn request() -> impl Future<Output = Response> + MaybeSend; // Works everywhere!§Critical Rule
Never use + Send directly in trait bounds for async functions in
wasm-compatible code. Always use + MaybeSend instead.
Traits§
- Maybe
Send - A trait that is
Sendon native targets, but auto-implemented on wasm.