Command

Type Alias Command 

Source
pub type Command = Box<dyn FnOnce() -> Option<Message> + Send + 'static>;
Expand description

A boxed function or closure that performs computations and optionally dispatches messages. All commands are processed in their own threads, so blocking commands are totally fine. Frequently, data needs to be passed to commands. Since commands take no arguments, a common solution to this is to build constructor functions.

§Example

// a constructor function
fn make_request_command(url: &str) -> Command {
    // it's okay to block since commands are multi threaded
    let text_response = reqwest::blocking::get(url).unwrap().text().unwrap();
     
    // the command itself
    Box::new(move || Some(Box::new(HttpResponse(text_response))))
}

Aliased Type§

pub struct Command(/* private fields */);