expression

Reserve enough time for a useful retry

Before delaying, check that the planned wait and a minimum useful attempt duration fit the remaining budget. This is admission policy, not a prediction of success. Recheck the real deadline after waiting. Expected stdout (not executed): true true false Common mistake: Waiting until the deadline and then discovering there is no time left for work.

Formal Syntax & Structure

rust syntaxrust
wait.checked_add(min_attempt).is_some_and(|cost| cost <= remaining)

Working Example

Example Snippetrust
fn main() {    use std::time::Duration;    let remaining = Duration::from_millis(200);    let min_attempt = Duration::from_millis(50);    for wait in [149, 150, 151] {        let cost = Duration::from_millis(wait).checked_add(min_attempt);        println!("{}", cost.is_some_and(|d| d <= remaining));    }}
Rust Reference