From 8cf55c702f2b953c78cae83cf7107d16b02746cd Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 3 Jul 2024 00:57:50 +0000 Subject: [PATCH] split time utils into unit Signed-off-by: Jason Volk --- src/core/utils/mod.rs | 16 +++------------- src/core/utils/time.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 src/core/utils/time.rs diff --git a/src/core/utils/mod.rs b/src/core/utils/mod.rs index 6ebab2c6..401775f7 100644 --- a/src/core/utils/mod.rs +++ b/src/core/utils/mod.rs @@ -9,11 +9,9 @@ pub mod mutex_map; pub mod string; pub mod sys; mod tests; +pub mod time; -use std::{ - cmp::{self, Ordering}, - time::{SystemTime, UNIX_EPOCH}, -}; +use std::cmp::{self, Ordering}; pub use bytes::{increment, u64_from_bytes, u64_from_u8, u64_from_u8x8}; pub use debug::slice_truncated as debug_slice_truncated; @@ -23,6 +21,7 @@ pub use json::{deserialize_from_str, to_canonical_object}; pub use mutex_map::MutexMap; pub use string::{random_string, str_from_bytes, string_from_bytes}; pub use sys::available_parallelism; +pub use time::millis_since_unix_epoch; use crate::Result; @@ -40,15 +39,6 @@ pub fn unwrap_infallible(result: Result) -> T { } } -#[must_use] -#[allow(clippy::as_conversions)] -pub fn millis_since_unix_epoch() -> u64 { - SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("time is valid") - .as_millis() as u64 -} - #[must_use] pub fn generate_keypair() -> Vec { let mut value = random_string(8).as_bytes().to_vec(); diff --git a/src/core/utils/time.rs b/src/core/utils/time.rs new file mode 100644 index 00000000..043950a8 --- /dev/null +++ b/src/core/utils/time.rs @@ -0,0 +1,11 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + +#[inline] +#[must_use] +#[allow(clippy::as_conversions)] +pub fn millis_since_unix_epoch() -> u64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("time is valid") + .as_millis() as u64 +}