Trait dioxus_core::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

Object Safety§

This trait is not object safe.

Implementors§

source§

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

source§

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