macro_rules! ms_expr {
($type:ty, $x:literal $(milliseconds)?$(millisecond)?$(msecs)?$(msec)?$(ms)?) => { ... };
($type:ty, $x:literal $(seconds)?$(second)?$(secs)?$(sec)?$(s)?) => { ... };
($type:ty, $x:literal $(minutes)?$(minute)?$(mins)?$(min)?$(m)?) => { ... };
($type:ty, $x:literal $(hours)?$(hour)?$(hrs)?$(hr)?$(h)?) => { ... };
($type:ty, $x:literal $(days)?$(day)?$(d)?) => { ... };
($type:ty, $x:literal $(weeks)?$(week)?$(w)?) => { ... };
($type:ty, $x:literal $(years)?$(year)?$(yrs)?$(yr)?$(y)?) => { ... };
}Expand description
Zero cost converter from human-like time into a number.
In the first argument, you need to pass type of your number (i64, f64 and etc).
The second argument is human-time construction, like 1 day, 2 h.
The output will be a number with type what you set in the first argument.
This macro will be precalculated in compilation time. Also, you can use ms_expr with constants:
use crate::ms_converter::ms_expr;
const VALUE: f64 = ms_expr!(f64, 2.5 hrs);
assert_eq!(VALUE, 9000000.)ยงUsage
use crate::ms_converter::ms_expr;
assert_eq!(ms_expr!(i64, 1 d), 86400000)