pub struct Callback<Args = (), Ret = ()> { /* private fields */ }
Expand description
The callback type generated by the rsx!
macro when an on
field is specified for components.
This makes it possible to pass move |evt| {}
style closures into components as property fields.
§Example
ⓘ
rsx! {
MyComponent { onclick: move |evt| {
tracing::debug!("clicked");
42
} }
}
#[derive(Props)]
struct MyProps {
onclick: Callback<MouseEvent, i32>,
}
fn MyComponent(cx: MyProps) -> Element {
rsx! {
button {
onclick: move |evt| println!("number: {}", cx.onclick.call(evt)),
}
}
}
Implementations§
source§impl<Args, Ret> Callback<Args, Ret>where
Args: 'static,
Ret: 'static,
impl<Args, Ret> Callback<Args, Ret>where
Args: 'static,
Ret: 'static,
sourcepub fn new<MaybeAsync, Marker>(
f: impl FnMut(Args) -> MaybeAsync + 'static,
) -> Callback<Args, Ret>where
MaybeAsync: SpawnIfAsync<Marker, Ret>,
pub fn new<MaybeAsync, Marker>(
f: impl FnMut(Args) -> MaybeAsync + 'static,
) -> Callback<Args, Ret>where
MaybeAsync: SpawnIfAsync<Marker, Ret>,
sourcepub fn leak(f: impl FnMut(Args) -> Ret + 'static) -> Callback<Args, Ret>
pub fn leak(f: impl FnMut(Args) -> Ret + 'static) -> Callback<Args, Ret>
Leak a new Callback
that will not be dropped unless it is manually dropped.
sourcepub fn call(&self, arguments: Args) -> Ret
pub fn call(&self, arguments: Args) -> Ret
Call this callback with the appropriate argument type
This borrows the callback using a RefCell. Recursively calling a callback will cause a panic.
sourcepub fn into_closure(self) -> impl FnMut(Args) + Copy + 'static
pub fn into_closure(self) -> impl FnMut(Args) + Copy + 'static
Create a impl FnMut + Copy
closure from the Closure type
Trait Implementations§
impl<Args, Ret> Copy for Callback<Args, Ret>
Auto Trait Implementations§
impl<Args, Ret> Freeze for Callback<Args, Ret>
impl<Args = (), Ret = ()> !RefUnwindSafe for Callback<Args, Ret>
impl<Args = (), Ret = ()> !Send for Callback<Args, Ret>
impl<Args = (), Ret = ()> !Sync for Callback<Args, Ret>
impl<Args, Ret> Unpin for Callback<Args, Ret>
impl<Args = (), Ret = ()> !UnwindSafe for Callback<Args, Ret>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.