refactor: create utils/hexrange utility modules

This commit is contained in:
Greg Heartsfield
2022-02-12 09:29:38 -06:00
parent 26a0ce2b32
commit 753df47443
6 changed files with 181 additions and 172 deletions
+15
View File
@@ -0,0 +1,15 @@
//! Common utility functions
use std::time::SystemTime;
/// Seconds since 1970.
pub fn unix_time() -> u64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map(|x| x.as_secs())
.unwrap_or(0)
}
/// Check if a string contains only hex characters.
pub fn is_hex(s: &str) -> bool {
s.chars().all(|x| char::is_ascii_hexdigit(&x))
}