1
0
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:
2019-12-28 09:45:56 +08:00
parent 7d5bb125ba
commit c4c6273c38
3 changed files with 19 additions and 1 deletions

View File

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

View File

@@ -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
View 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()
}