mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
add time, iff!
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust_util"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "Hatter's Rust Util"
|
||||
|
||||
@@ -13,6 +13,15 @@ pub mod util_cmd;
|
||||
pub mod util_msg;
|
||||
pub mod util_size;
|
||||
pub mod util_file;
|
||||
pub mod util_time;
|
||||
|
||||
/// iff!(condition, result_when_true, result_when_false)
|
||||
#[macro_export]
|
||||
macro_rules! iff {
|
||||
($c:expr, $t:expr, $f:expr) => {
|
||||
if $c { $t } else { $f }
|
||||
};
|
||||
}
|
||||
|
||||
pub type XResult<T> = Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
|
||||
9
src/util_time.rs
Normal file
9
src/util_time.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub fn get_current_secs() -> u64 {
|
||||
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()
|
||||
}
|
||||
|
||||
pub fn get_current_millis() -> u128 {
|
||||
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis()
|
||||
}
|
||||
Reference in New Issue
Block a user