Struct wasm_react::callback::Callback
source · [−]pub struct Callback<T, U = ()> { /* private fields */ }
Expand description
This is a simplified, reference-counted wrapper around an FnMut
Rust
closure that may be called from JS when T
and U
allow.
It only supports closures with exactly one input argument and some return
value. Memory management is handled by Rust. Whenever Rust drops all clones
of the Callback
, the closure will be dropped and the function cannot be
called from JS anymore.
Use Void
to simulate a callback with no arguments.
Implementations
sourceimpl<T, U> Callback<T, U> where
T: 'static,
U: 'static,
impl<T, U> Callback<T, U> where
T: 'static,
U: 'static,
sourcepub fn new(f: impl FnMut(T) -> U + 'static) -> Self
pub fn new(f: impl FnMut(T) -> U + 'static) -> Self
Creates a new Callback
from a Rust closure.
sourcepub fn to_closure(&self) -> impl FnMut(T) -> U + 'static
pub fn to_closure(&self) -> impl FnMut(T) -> U + 'static
Returns a Rust closure from the callback.
sourcepub fn premap<V>(&self, f: impl FnMut(V) -> T + 'static) -> Callback<V, U>
pub fn premap<V>(&self, f: impl FnMut(V) -> T + 'static) -> Callback<V, U>
Returns a new Callback
by prepending the given closure to the callback.
sourcepub fn postmap<V>(&self, f: impl FnMut(U) -> V + 'static) -> Callback<T, V>
pub fn postmap<V>(&self, f: impl FnMut(U) -> V + 'static) -> Callback<T, V>
Returns a new Callback
by appending the given closure to the callback.
sourcepub fn as_js(&self) -> Ref<'_, JsValue> where
T: FromWasmAbi,
U: IntoWasmAbi,
pub fn as_js(&self) -> Ref<'_, JsValue> where
T: FromWasmAbi,
U: IntoWasmAbi,
Returns a reference to JsValue
of the callback.
Trait Implementations
sourceimpl<T, U> From<PersistedCallback<T, U>> for Callback<T, U>
impl<T, U> From<PersistedCallback<T, U>> for Callback<T, U>
sourcefn from(value: PersistedCallback<T, U>) -> Self
fn from(value: PersistedCallback<T, U>) -> Self
Converts to this type from the input type.
impl<T, U> Eq for Callback<T, U>
Auto Trait Implementations
impl<T, U = ()> !RefUnwindSafe for Callback<T, U>
impl<T, U = ()> !Send for Callback<T, U>
impl<T, U = ()> !Sync for Callback<T, U>
impl<T, U> Unpin for Callback<T, U>
impl<T, U = ()> !UnwindSafe for Callback<T, U>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more