Macro itron_solid_asp3::time::duration[][src]

pub macro duration {
    ($kind : tt : $value : literal) => { ... },
    (s : $value : expr) => { ... },
    (ms : $value : expr) => { ... },
    (us : $value : expr) => { ... },
    (μs : $value : expr) => { ... },
    (ns : $value : expr) => { ... },
    (0) => { ... },
}
This is supported on crate features unstable and nightly only.
Expand description

Construct a Duration value in a concise syntax. Panics if the specified duration cannot be represented by Duration.

Examples

use itron::time::{duration, Duration};
assert_eq!(Duration::ZERO, duration!(0));
assert_eq!(Duration::from_millis(42).unwrap(), duration!(ms: 42));

Panics if the value is out of range:

let _ = duration!(s: 0x7ffffffffffffff * 2);

Once inline_const lands, it will be possible to do the check at compile-time:

#![feature(inline_const)]
let _ = const { duration!(s: 0x7ffffffffffffff * 2) };

Literal values are validated at compile-time regardless of whether const { ... } is used or not:

let _ = duration!(s: 0xfffffffffffffff);
// Wrap the expression with `( ... )` to avoid the above behavior and
// cause a runtime panic.
let _ = duration!(s: (0xfffffffffffffff));