If you need to access the process starting time from several functions, then instead of passing it around or instead of using the caching we could use the std::sync::LazyLock.
examples/fixed-start-time/src/main.rs
use std::sync::LazyLock;
use std::time::SystemTime;
static START_TIME: LazyLock<SystemTime> = LazyLock::new(SystemTime::now);
fn main() {
print_start_time();
print_start_time();
}
fn print_start_time() {
println!("{:?}", *START_TIME);
}
Output
examples/fixed-start-time/out.txt
SystemTime { tv_sec: 1781242831, tv_nsec: 637877888 }
SystemTime { tv_sec: 1781242831, tv_nsec: 637877888 }