Skip to main content

Module maybe_send

Module maybe_send 

Source
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§

MaybeSend
A trait that is Send on native targets, but auto-implemented on wasm.