split time utils into unit

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-03 00:57:50 +00:00
parent 3b9fba233c
commit 8cf55c702f
2 changed files with 14 additions and 13 deletions

View file

@ -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<T>(result: Result<T, std::convert::Infallible>) -> 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<u8> {
let mut value = random_string(8).as_bytes().to_vec();

11
src/core/utils/time.rs Normal file
View file

@ -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
}