1use std::{
4 sync::LazyLock,
5 time::{SystemTime, UNIX_EPOCH},
6};
7
8macro_rules! define_init_lazylock_statics {
14 ($(
15 $( #[$attr:meta] )*
16 $name:ident: $t:ty = $init_fn:expr_2021;
17 )*) => {
18 pub fn init_lazylock_statics() {
20 $(
21 LazyLock::force(&$name);
22 )*
23 }
24
25 $(
26 $(#[$attr])*
27 pub static $name: LazyLock<$t> = LazyLock::new(|| $init_fn);
28 )*
29 };
30}
31
32define_init_lazylock_statics! {
33 START_INSTANT: SystemTime = SystemTime::now();
35
36 START_INSTANT_UNIX: u64 = START_INSTANT
38 .duration_since(UNIX_EPOCH)
39 .expect("Failed to set `cuprated` startup time.")
40 .as_secs();
41}
42
43#[cfg(test)]
44mod test {
45 use super::*;
46
47 #[test]
49 fn start_instant_unix() {
50 assert!(*START_INSTANT_UNIX > 1727399233);
52 }
53}