std-type

SystemTimeError::duration: recover magnitude

SystemTimeError exposes how far the argument is ahead of the receiver in a failed duration_since call. The returned duration is nonnegative. The application supplies the sign or decides how to handle clock reversal. Expected stdout (not executed): 7 Common mistake: Using the magnitude as a positive elapsed interval without preserving direction.

Formal Syntax & Structure

rust syntaxrust
err.duration() -> Duration

Working Example

Example Snippetrust
fn main() {    use std::time::{Duration, UNIX_EPOCH};    let a = UNIX_EPOCH + Duration::from_secs(2);    let b = UNIX_EPOCH + Duration::from_secs(9);    let err = a.duration_since(b).unwrap_err();    println!("{}", err.duration().as_secs());}
Rust Reference