u-num-it
A simple procedural macro for matching typenum::consts in a given range or array.
It helps you write concise numeric typenum matches like:
use ;
let x: isize = 3;
let y: isize = u_num_it!;
assert_eq!;
Or with an array of arbitrary numbers:
use ;
let x: isize = 8;
let y: isize = u_num_it!;
assert_eq!;
Instead of writing the explicit (and repetitive) match yourself:
use ;
let x: isize = 3;
let y: isize = match x ;
assert_eq!;
NumType is available inside each match arm, bound to the concrete typenum type for the matched value:
use ;
let x: isize = 3;
let y: isize = u_num_it!;
assert_eq!;
Notes
- Use
ToIntfor signed/unsigned integer typenum constants (P*,N*). - Use
to_u8()for bit types (False=B0,True=B1if you ever introduce it), casting as needed. - Avoid mixing
PandUin the same macro call (the macro enforces this). - Literal
0andFalseare treated as the same value; don't use both in one invocation.