Macro itron_asp3::time::timeout[][src]

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

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

Examples

use itron::time::{timeout, Timeout};
assert_eq!(Timeout::ZERO, timeout!(0));
assert_eq!(Timeout::FOREVER, timeout!(infinity));
assert_eq!(Timeout::from_millis(42).unwrap(), timeout!(ms: 42));

Panics if the value is out of range:

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

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

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

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

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