Skip to main content

ScopedClosure

Struct ScopedClosure 

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

Source

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,

Source

pub fn new<F>(t: F) -> Self
where F: IntoWasmClosure<T> + MaybeUnwindSafe + 'static,

Source

pub fn own<F>(t: F) -> Self
where F: IntoWasmClosure<T> + MaybeUnwindSafe + 'static,

Source

pub fn own_aborting<F>(t: F) -> Self
where F: IntoWasmClosure<T> + 'static,

Source

pub fn own_assert_unwind_safe<F>(t: F) -> Self
where F: IntoWasmClosure<T> + 'static,

Source

pub fn wrap<F>(data: Box<F>) -> Self
where F: IntoWasmClosure<T> + ?Sized + MaybeUnwindSafe,

Source

pub fn wrap_aborting<F>(data: Box<F>) -> Self
where F: IntoWasmClosure<T> + ?Sized,

Source

pub fn wrap_assert_unwind_safe<F>(data: Box<F>) -> Self
where F: IntoWasmClosure<T> + ?Sized,

Source

pub fn borrow<'a, F>(t: &'a F) -> ScopedClosure<'a, T::Static>
where F: IntoWasmClosureRef<T> + MaybeUnwindSafe + ?Sized,

Source

pub fn borrow_aborting<'a, F>(t: &'a F) -> ScopedClosure<'a, T::Static>
where F: IntoWasmClosureRef<T> + ?Sized,

Source

pub fn borrow_assert_unwind_safe<'a, F>( t: &'a F, ) -> ScopedClosure<'a, T::Static>
where F: IntoWasmClosureRef<T> + ?Sized,

Source

pub fn borrow_mut<'a, F>(t: &'a mut F) -> ScopedClosure<'a, T::Static>
where F: IntoWasmClosureRefMut<T> + MaybeUnwindSafe + ?Sized,

Source

pub fn borrow_mut_aborting<'a, F>(t: &'a mut F) -> ScopedClosure<'a, T::Static>
where F: IntoWasmClosureRefMut<T> + ?Sized,

Source

pub fn borrow_mut_assert_unwind_safe<'a, F>( t: &'a mut F, ) -> ScopedClosure<'a, T::Static>
where F: IntoWasmClosureRefMut<T> + ?Sized,

Source

pub fn once<F, A, R>(fn_once: F) -> Self
where 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.

Source

pub fn once_aborting<F, A, R>(fn_once: F) -> Self
where F: WasmClosureFnOnceAbort<T, A, R>,

Source

pub fn once_assert_unwind_safe<F, A, R>(fn_once: F) -> Self
where F: WasmClosureFnOnceAbort<T, A, R>,

Source

pub fn forget(self)

Forgets the closure, leaking it.

Source

pub fn into_js_value(self) -> JsValue

Converts the Closure into a JsValue.

Source

pub fn once_into_js<F, A, R>(fn_once: F) -> JsValue
where 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<T: ?Sized> AsRef<JsValue> for ScopedClosure<'_, T>

Source§

fn as_ref(&self) -> &JsValue

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<F: ?Sized> BinaryEncode for &ScopedClosure<'_, F>

Source§

fn encode(self, encoder: &mut EncodedData)

Source§

impl<T> Debug for ScopedClosure<'_, T>
where T: ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized> Drop for ScopedClosure<'_, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: ?Sized> EncodeTypeDef for ScopedClosure<'_, T>

Source§

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>

Source§

type Repr = ScopedClosure<'static, dyn FnMut()>

Source§

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>
where T: Send + ?Sized,

§

impl<'a, T> Sync for ScopedClosure<'a, T>
where T: Sync + ?Sized,

§

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> 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> FromWasmAbi for T

Source§

unsafe fn from_abi(js: u32) -> Self
where Self: Sized + FromAbiId,

Recreate a JS-reference-like value from a heap id. Read more
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> IntoWasmAbi for T

Source§

fn into_abi(self) -> u32
where Self: Sized + IntoAbiId,

Source§

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

Source§

unsafe fn ref_from_abi(js: u32) -> AbiRef<Self>
where Self: Sized + FromAbiId,

Recreate a non-dropping reference anchor from a heap id. Read more
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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = <Self as ErasableGeneric>::Repr>,

Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = <Self as ErasableGeneric>::Repr>,

Source§

impl<T> OptionFromWasmAbi for T
where T: FromWasmAbi,

Source§

impl<T> OptionIntoWasmAbi for T
where T: IntoWasmAbi,

Source§

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