std-method
Instant::saturating_duration_since: expired intervals
Calculate a nonnegative interval, clamping an earlier receiver to zero. A useful use is a remaining deadline budget: after the deadline, the remaining time should be zero. Expected stdout (not executed): true Common mistake: Using a saturated difference where backwards clock readings need investigation.
Formal Syntax & Structure
rust syntaxrust
a.saturating_duration_since(b: Instant) -> DurationWorking Example
Example Snippetrust
fn main() { use std::time::{Duration, Instant}; let base = Instant::now(); let deadline = base.checked_add(Duration::from_millis(100)).unwrap(); let late = base.checked_add(Duration::from_millis(120)).unwrap(); println!("{}", deadline.saturating_duration_since(late).is_zero());}