pub trait SpawnIfAsync<Marker, Ret = ()>: Sized {
// Required method
fn spawn(self) -> Ret;
}
Expand description
A helper trait for Callback
s that allows functions to accept a Callback
that may return an async block which will automatically be spawned.
use dioxus::prelude::*;
fn accepts_fn<Ret: dioxus_core::SpawnIfAsync<Marker>, Marker>(callback: impl FnMut(u32) -> Ret + 'static) {
let callback = Callback::new(callback);
}
// You can accept both async and non-async functions
accepts_fn(|x| async move { println!("{}", x) });
accepts_fn(|x| println!("{}", x));
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.