std-method
SystemTime::elapsed: fallible wall-clock difference
Compare a stored wall-clock timestamp with the current clock. The result can be an error if the stored timestamp is later than the current reading. This fixture accepts either branch, so it does not depend on the current date or timing. Expected stdout (not executed): comparison handled Common mistake: Using SystemTime::elapsed for a latency benchmark and assuming success.
Formal Syntax & Structure
rust syntaxrust
t.elapsed() -> Result<Duration, SystemTimeError>Working Example
Example Snippetrust
fn main() { use std::time::UNIX_EPOCH; match UNIX_EPOCH.elapsed() { Ok(_) => println!("comparison handled"), Err(_) => println!("comparison handled"), }}