pub struct Closure<T>where
T: ?Sized,{ /* private fields */ }Expand description
Closure type for passing Rust closures to JavaScript.
Implementations§
Source§impl<T> Closure<T>where
T: ?Sized,
impl<T> Closure<T>where
T: ?Sized,
pub fn new<M, F>(f: F) -> Closure<T>where
F: IntoClosure<M, Closure<T>>,
Sourcepub fn once<F, M>(fn_once: F) -> Closure<T>where
F: WasmClosureFnOnce<T, M>,
pub fn once<F, M>(fn_once: F) -> Closure<T>where
F: WasmClosureFnOnce<T, M>,
Create a Closure from a function that can only be called once.
Since we have no way of enforcing that JS cannot attempt to call this
FnOnce more than once, this produces a Closure<dyn FnMut(A...) -> R>
that will panic if called more than once.
Source§impl<T> Closure<T>where
T: ?Sized,
impl<T> Closure<T>where
T: ?Sized,
Sourcepub fn wrap<M>(data: Box<T>) -> Closure<T>where
T: WasmClosure<M>,
pub fn wrap<M>(data: Box<T>) -> Closure<T>where
T: WasmClosure<M>,
Wrap a boxed closure to create a Closure.
This is the classic wasm-bindgen API for creating closures from boxed trait objects.
Sourcepub fn into_js_value(self) -> JsValue
pub fn into_js_value(self) -> JsValue
Converts the Closure into a JsValue.
Sourcepub fn once_into_js<F, M>(fn_once: F) -> JsValuewhere
F: WasmClosureFnOnce<T, M>,
pub fn once_into_js<F, M>(fn_once: F) -> JsValuewhere
F: WasmClosureFnOnce<T, M>,
Create a Closure from a function that can only be called once,
and return the underlying JsValue directly.
This is a convenience method that combines once and into_js_value.
Trait Implementations§
Source§impl<F> BatchableResult for Closure<F>where
F: ?Sized,
impl<F> BatchableResult for Closure<F>where
F: ?Sized,
Source§impl<F> BinaryDecode for Closure<F>where
F: ?Sized,
impl<F> BinaryDecode for Closure<F>where
F: ?Sized,
fn decode(decoder: &mut DecodedData<'_>) -> Result<Closure<F>, DecodeError>
Source§impl<F> BinaryEncode for &Closure<F>where
F: ?Sized,
impl<F> BinaryEncode for &Closure<F>where
F: ?Sized,
fn encode(self, encoder: &mut EncodedData)
Source§impl<F> BinaryEncode for Closure<F>where
F: ?Sized,
impl<F> BinaryEncode for Closure<F>where
F: ?Sized,
fn encode(self, encoder: &mut EncodedData)
Source§impl<T> EncodeTypeDef for Closure<T>where
T: ?Sized,
impl<T> EncodeTypeDef for Closure<T>where
T: ?Sized,
Source§fn encode_type_def(buf: &mut Vec<u8>)
fn encode_type_def(buf: &mut Vec<u8>)
Encode this type’s definition into the buffer.
For primitives, this is just the TypeTag byte.
For callbacks, this includes param count, param types, and return type.
Auto Trait Implementations§
impl<T> Freeze for Closure<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Closure<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for Closure<T>
impl<T> Sync for Closure<T>
impl<T> Unpin for Closure<T>where
T: ?Sized,
impl<T> UnwindSafe for Closure<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more