expression

Disabled select branches and else

A false precondition prevents polling that branch for this select invocation. Its future expression is still evaluated. Provide else when all branches can be disabled or fail to match. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 0 Common mistake: Putting side effects in a future-construction expression and expecting the guard to prevent them.

Formal Syntax & Structure

rust syntaxrust
tokio::select! { value = future, if condition => handler, else => fallback }

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() {    let enabled = false;    let result = tokio::select! {        n = async { 4 }, if enabled => n,        else => 0,    };    println!("{result}");}
Rust Reference