20 lines
445 B
Rust
20 lines
445 B
Rust
//! Small injectable time boundary for deterministic activity records.
|
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
pub trait Clock {
|
|
fn now(&self) -> String;
|
|
}
|
|
|
|
pub struct SystemClock;
|
|
|
|
impl Clock for SystemClock {
|
|
fn now(&self) -> String {
|
|
let seconds = SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.map(|duration| duration.as_secs())
|
|
.unwrap_or(0);
|
|
format!("unix:{seconds}")
|
|
}
|
|
}
|