expression
Overall budget across HTTP attempts
Model an outer deadline independently of per-request limits. Count all attempted operations, delays and decoding against one total budget. A timeout does not guarantee that a remote side effect was cancelled. Original policy model, not an HTTP implementation. Expected stdout (not executed): 400 250 0 Common mistake: Resetting a total budget on each retry or assuming timeout means the server did nothing.
Formal Syntax & Structure
rust syntaxrust
remaining = total.saturating_sub(elapsed)Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use std::time::Duration; let total = Duration::from_millis(1000); for elapsed in [200, 750, 1100] { let left = total.saturating_sub(Duration::from_millis(elapsed)); let attempt = left.min(Duration::from_millis(400)); println!("{}", attempt.as_millis()); }}