Trait SpawnIfAsync

Source
pub trait SpawnIfAsync<Marker, Ret = ()>: Sized {
    // Required method
    fn spawn(self) -> Ret;
}
Expand description

A helper trait for Callbacks 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§

Source

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block

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.

Implementors§

Source§

impl SpawnIfAsync<()> for Result<()>

Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret