Skip to main content

r

Macro r 

Source
macro_rules! r {
    ([$min:literal $max:literal] $x:expr) => { ... };
    ([] $v:expr) => { ... };
    (-$min:tt..=$max:tt) => { ... };
    (-$min:tt..=-$max:tt) => { ... };
    ($min:tt..=$max:tt) => { ... };
    ($v:literal) => { ... };
    ($v:tt) => { ... };
}
Expand description

Create a ranged value or a range at compile time

Warning: ensure #![feature(adt_const_params)] is enabled.

ยงExample

// Explicit bounds:
let a = r!([0 42] 23);  // Ranged<0, 42> with a value 23
// Type inference:
let b: Ranged<0, 100> = r!([] 42);  // Ranged<0, 100> with a value 42
// "Constant" value:
let c = r!(10);  // Zero-sized Ranged<10, 10> with a value 10
//Range:
for i in r!(0..=9){
    let v: Ranged<0,9> = i; 
}