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: 'static, Ret: 'static> Callback<Args, Ret>
impl<Args: 'static, Ret: 'static> Callback<Args, Ret>
Sourcepub fn new<MaybeAsync: SpawnIfAsync<Marker, Ret>, Marker>(
f: impl FnMut(Args) -> MaybeAsync + 'static,
) -> Self
pub fn new<MaybeAsync: SpawnIfAsync<Marker, Ret>, Marker>( f: impl FnMut(Args) -> MaybeAsync + 'static, ) -> Self
Sourcepub fn leak(f: impl FnMut(Args) -> Ret + 'static) -> Self
pub fn leak(f: impl FnMut(Args) -> Ret + 'static) -> Self
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) -> Ret + Copy + 'static
pub fn into_closure(self) -> impl FnMut(Args) -> Ret + 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§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.