[go: up one dir, main page]

int

Macro int 

Source
macro_rules! int {
    ($min:literal, $max:literal) => { ... };
}
Available on crate feature macros only.
Expand description

A macro to define a ranged integer with an automatically computed inner type.

The minimum and maximum values are provided as integer literals, and the macro will compute an appropriate inner type to represent the range. This will be the smallest integer type that can store both the minimum and maximum values, with a preference for unsigned types if both are possible. To specifically request a signed or unsigned type, you can append a i or u suffix to either or both of the minimum and maximum values, respectively.

§Examples

int!(0, 100);  // RangedU8<0, 100>
int!(0i, 100); // RangedI8<0, 100>
int!(-5, 5);   // RangedI8<-5, 5>
int!(-5u, 5);  // compile error (-5 cannot be unsigned)