expression

JoinHandle: distinguish task failure from application failure

The outer result represents task completion status; a task may itself return a Result. Keep the two layers distinct to report cancellation, panic and application errors correctly. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): application: invalid record Common mistake: Interpreting Ok from joining as proof that the application operation succeeded.

Formal Syntax & Structure

rust syntaxrust
handle.await -> Result<T, JoinError>

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    let task = tokio::spawn(async { Err::<u32, &str>("invalid record") });    match task.await {        Ok(Ok(n)) => println!("value {n}"),        Ok(Err(e)) => println!("application: {e}"),        Err(_) => println!("task failed"),    }}
Rust Reference