Skip to main content

WasmSend

Struct WasmSend 

Source
pub struct WasmSend<T>(/* private fields */);
Expand description

Wrapper that unconditionally implements Send on WASM.

On native, WasmSend<T> is Send only if T: Send (no magic). On WASM, WasmSend<T> is always Send, allowing !Send types (like Writer wrapping a JsValue-backed response stream) to be moved into a Web Worker.

§Safety contract

The caller must ensure that:

  • The wrapped value is not actively used across threads simultaneously.
  • When transferring to a Web Worker, any !Send JS-backed values inside must be None/uninitialized at transfer time and only populated inside the target worker (where JS objects belong to the local context).

FileDownloader satisfies this: writer is None when moved to the Worker, and ensure_writer() creates the HTTP stream inside the Worker.

Implementations§

Source§

impl<T> WasmSend<T>

Source

pub fn new(value: T) -> Self

Wrap a value.

Source

pub fn get(&self) -> &T

Immutable access.

Source

pub fn get_mut(&mut self) -> &mut T

Mutable access.

Trait Implementations§

Source§

impl<T: Send> Send for WasmSend<T>

Available on non-WebAssembly only.

Auto Trait Implementations§

§

impl<T> Freeze for WasmSend<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for WasmSend<T>
where T: RefUnwindSafe,

§

impl<T> Sync for WasmSend<T>
where T: Sync,

§

impl<T> Unpin for WasmSend<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for WasmSend<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for WasmSend<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,