macro_rules! unchecked_div_by_const {
    ($num:expr, $den:expr) => { ... };
}
Expand description

Convenience macro for doing integer division where the operation’s safety can be checked at compile-time.

Since unchecked_div_by_const!() is supposed to fail at compile-time, abuse doctests to cover failure modes

Examples

Literal denominator div-by-zero fails:

let _ = unchecked_div_by_const!(10, 0);

Const denominator div-by-zero fails:

const D: u64 = 0;
let _ = unchecked_div_by_const!(10, D);

Non-const denominator fails:

let d = 0;
let _ = unchecked_div_by_const!(10, d);

Literal denominator div-by-zero fails:

const N: u64 = 10;
let _ = unchecked_div_by_const!(N, 0);

Const denominator div-by-zero fails:

const N: u64 = 10;
const D: u64 = 0;
let _ = unchecked_div_by_const!(N, D);

Non-const denominator fails:

let d = 0;
let _ = unchecked_div_by_const!(N, d);

Literal denominator div-by-zero fails:

let n = 10;
let _ = unchecked_div_by_const!(n, 0);

Const denominator div-by-zero fails:

let n = 10;
const D: u64 = 0;
let _ = unchecked_div_by_const!(n, D);

Non-const denominator fails:

let n = 10;
let d = 0;
let _ = unchecked_div_by_const!(n, d);