expression
Separate timeout from operation failure
If the inner future returns a Result, expiration and an application error are distinct outcomes. Handle the layers independently. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): operation: not found Common mistake: Reporting every application error as a timeout.
Formal Syntax & Structure
rust syntaxrust
Result<Result<T, E>, Elapsed>Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() { use tokio::time::{timeout, Duration}; let result = timeout(Duration::from_secs(1), async { Err::<u32, _>("not found") }).await; match result { Ok(Ok(value)) => println!("{value}"), Ok(Err(message)) => println!("operation: {message}"), Err(_) => println!("deadline"), }}