Is it possible to specify a global constant for a struct like a time::Duration
?
const DELAY_TIME: time::Duration = ???
...
thread::sleep(DELAY_TIME);
Is it possible to specify a global constant for a struct like a time::Duration
?
const DELAY_TIME: time::Duration = ???
...
thread::sleep(DELAY_TIME);
A Duration
cannot be computed at compile-time, so you have two options:
u64
and a u32
)Duration
in a lazy_static
(Requires dynamic allocation, atomic locking, and a dependent crate. Not recommended here).Here's how to do the first option:
use std::time::Duration;
use std::thread::sleep;
const DELAY_SECONDS: u64 = 1;
const DELAY_NANO_SECONDS: u32 = 0;
fn main() {
sleep(Duration::new(DELAY_SECONDS, DELAY_NANO_SECONDS));
}