pub struct ScopedClosure<'a, T: ?Sized> { /* private fields */ }Expand description
Borrowed or owned closure handle for passing Rust closures to JavaScript.
Implementations§
Source§impl<'a, T> ScopedClosure<'a, T>where
T: ?Sized + WasmClosure,
impl<'a, T> ScopedClosure<'a, T>where
T: ?Sized + WasmClosure,
Sourcepub fn as_js_value(&self) -> &JsValue
pub fn as_js_value(&self) -> &JsValue
Returns the JavaScript function value for this closure.
Source§impl<T> ScopedClosure<'static, T>where
T: ?Sized + WasmClosure,
impl<T> ScopedClosure<'static, T>where
T: ?Sized + WasmClosure,
pub fn new<F>(t: F) -> Selfwhere
F: IntoWasmClosure<T> + MaybeUnwindSafe + 'static,
pub fn own<F>(t: F) -> Selfwhere
F: IntoWasmClosure<T> + MaybeUnwindSafe + 'static,
pub fn own_aborting<F>(t: F) -> Selfwhere
F: IntoWasmClosure<T> + 'static,
pub fn own_assert_unwind_safe<F>(t: F) -> Selfwhere
F: IntoWasmClosure<T> + 'static,
pub fn wrap<F>(data: Box<F>) -> Selfwhere
F: IntoWasmClosure<T> + ?Sized + MaybeUnwindSafe,
pub fn wrap_aborting<F>(data: Box<F>) -> Selfwhere
F: IntoWasmClosure<T> + ?Sized,
pub fn wrap_assert_unwind_safe<F>(data: Box<F>) -> Selfwhere
F: IntoWasmClosure<T> + ?Sized,
pub fn borrow<'a, F>(t: &'a F) -> ScopedClosure<'a, T::Static>where
F: IntoWasmClosureRef<T> + MaybeUnwindSafe + ?Sized,
pub fn borrow_aborting<'a, F>(t: &'a F) -> ScopedClosure<'a, T::Static>where
F: IntoWasmClosureRef<T> + ?Sized,
pub fn borrow_assert_unwind_safe<'a, F>(
t: &'a F,
) -> ScopedClosure<'a, T::Static>where
F: IntoWasmClosureRef<T> + ?Sized,
pub fn borrow_mut<'a, F>(t: &'a mut F) -> ScopedClosure<'a, T::Static>where
F: IntoWasmClosureRefMut<T> + MaybeUnwindSafe + ?Sized,
pub fn borrow_mut_aborting<'a, F>(t: &'a mut F) -> ScopedClosure<'a, T::Static>where
F: IntoWasmClosureRefMut<T> + ?Sized,
pub fn borrow_mut_assert_unwind_safe<'a, F>(
t: &'a mut F,
) -> ScopedClosure<'a, T::Static>where
F: IntoWasmClosureRefMut<T> + ?Sized,
Sourcepub fn once<F, A, R>(fn_once: F) -> Selfwhere
F: WasmClosureFnOnce<T, A, R> + MaybeUnwindSafe,
pub fn once<F, A, R>(fn_once: F) -> Selfwhere
F: WasmClosureFnOnce<T, A, R> + MaybeUnwindSafe,
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.
pub fn once_aborting<F, A, R>(fn_once: F) -> Selfwhere
F: WasmClosureFnOnceAbort<T, A, R>,
pub fn once_assert_unwind_safe<F, A, R>(fn_once: F) -> Selfwhere
F: WasmClosureFnOnceAbort<T, A, R>,
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, A, R>(fn_once: F) -> JsValuewhere
F: WasmClosureFnOnce<T, A, R> + MaybeUnwindSafe,
pub fn once_into_js<F, A, R>(fn_once: F) -> JsValuewhere
F: WasmClosureFnOnce<T, A, R> + MaybeUnwindSafe,
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: ?Sized> BinaryEncode for &ScopedClosure<'_, F>
impl<F: ?Sized> BinaryEncode for &ScopedClosure<'_, F>
fn encode(self, encoder: &mut EncodedData)
Source§impl<T> Debug for ScopedClosure<'_, T>where
T: ?Sized,
impl<T> Debug for ScopedClosure<'_, T>where
T: ?Sized,
Source§impl<T: ?Sized> Drop for ScopedClosure<'_, T>
impl<T: ?Sized> Drop for ScopedClosure<'_, T>
Source§impl<T: ?Sized> EncodeTypeDef for ScopedClosure<'_, T>
impl<T: ?Sized> EncodeTypeDef for ScopedClosure<'_, T>
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.
Source§impl<T: ?Sized> ErasableGeneric for ScopedClosure<'_, T>
impl<T: ?Sized> ErasableGeneric for ScopedClosure<'_, T>
type Repr = ScopedClosure<'static, dyn FnMut()>
impl<T: ?Sized> Unpin for ScopedClosure<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for ScopedClosure<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for ScopedClosure<'a, T>where
T: RefUnwindSafe + ?Sized,
impl<'a, T> Send for ScopedClosure<'a, T>
impl<'a, T> Sync for ScopedClosure<'a, T>
impl<'a, T> UnsafeUnpin for ScopedClosure<'a, T>where
T: ?Sized,
impl<'a, T> UnwindSafe for ScopedClosure<'a, 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