How to Calculate Duration Between Two Times in Rust

Calculate the time difference in Rust by subtracting two `Instant` values to get a `Duration`.

Use std::time::Duration to represent the time span and subtract two Instant values to calculate the difference.

use std::time::{Duration, Instant};

fn main() {
    let start = Instant::now();
    // Simulate work
    std::thread::sleep(Duration::from_secs(2));
    let end = Instant::now();

    let duration = end - start;
    println!("Elapsed: {:?}", duration);
}