Skip to main content

TaskName

Trait TaskName 

Source
pub trait TaskName: Sized + 'static {
    type Output: Send + 'static;

    const NAME: &'static str;

    // Provided method
    fn task<F>(
        future: F,
    ) -> impl NamedTask<Output = Self::Output> + Send + 'static
       where F: Future<Output = Self::Output> + Send + 'static { ... }
}
Expand description

A task name. Declare one with task_name!, never by hand.

The name is a type, so a test that answers SaveNote with a value of the wrong type does not compile, and NAME is the type’s module path, so two names can only share a string if they are the same type.

Required Associated Constants§

Source

const NAME: &'static str

The type’s path, such as notes::api::SaveNote.

Required Associated Types§

Source

type Output: Send + 'static

What the named future returns.

Provided Methods§

Source

fn task<F>(future: F) -> impl NamedTask<Output = Self::Output> + Send + 'static
where F: Future<Output = Self::Output> + Send + 'static,

Names a future. Its output must be this name’s output. The one way to start a named task: Task::perform(SaveNote::task(api.save(note)), Message::Saved).

Without the control feature this returns future itself; with it, a [Named] wrapper a harness can control. Either way the type is opaque, so app code compiles the same in both.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§