tcp::util

Module time

source
Expand description

Traits that provide an abstract interface for time-related operations, modelled after std::time.

fn add_durations<T: tcp::util::time::Duration>(x1: T, x2: T) -> T {
    x1 + x2
}

use std::time::Duration;
assert_eq!(
    add_durations(Duration::from_secs(1), Duration::from_millis(2)),
    Duration::from_secs(1) + Duration::from_millis(2),
);

Traitsยง

  • A trait for time durations that follow the API of std::time::Duration. This is useful for code that should work with not just the real time, but also simulated time.
  • A trait for time instants that follow the API of std::time::Instant. This is useful for code that should work with not just the real time, but also simulated time.