#range #typenum #matching #macro #consts #match #type

macro u-num-it

typenum macro for matching types from a given range

3 releases

0.1.2 Mar 16, 2024
0.1.1 Mar 14, 2024
0.1.0 Mar 14, 2024

#314 in Procedural macros

Download history 289/week @ 2024-03-13 33/week @ 2024-03-20 15/week @ 2024-03-27 40/week @ 2024-04-03

92 downloads per month

MIT license

9KB
173 lines

u-num-it

A simple procedural macros for matching typenum::consts in a given range.

Helps you to write

let x:isize = 3;

u_num_it!(-5..5, match x {
    N => {
        N::new()
    },
    False => {
        False::new()
    },
    P => {
        P::new()
    }
})

instead of

let x = 3;
match x {
    -5 => {
        typenum::consts::N5::new();
    }
    -4 => {
        typenum::consts::N4::new();
    }
    -3 => {
        typenum::consts::N3::new();
    }
    -2 => {
        typenum::consts::N2::new();
    }
    -1 => {
        typenum::consts::N1::new();
    }
    0 => {
        typenum::consts::False::new();
    }
    1 => {
        typenum::consts::P1::new();
    }
    2 => {
        typenum::consts::P2::new();
    }
    3 => {
        typenum::consts::P3::new();
    }
    4 => {
        typenum::consts::P4::new();
    }
    i => {
        panic!()
    }
}

Dependencies

~300–750KB
~18K SLoC