#enums #usize #from #into

macro derive-to-usize

Derive for From and Into usize

1 unstable release

0.1.0 Jun 25, 2024

#17 in #into

Download history 171/week @ 2024-06-25 23/week @ 2024-07-02 1/week @ 2024-07-16 8/week @ 2024-07-23 10/week @ 2024-07-30 1/week @ 2024-08-06 4/week @ 2024-08-13 2/week @ 2024-08-20 25/week @ 2024-08-27 6/week @ 2024-09-03 19/week @ 2024-09-10 16/week @ 2024-09-17 26/week @ 2024-09-24 20/week @ 2024-10-01 4/week @ 2024-10-08

78 downloads per month

MIT/Apache

3KB

Derive for From and Into usize.

use derive_into::ToUsize;
#[derive(ToUsize)]
enum Foo {
    Bar,
    E
}
assert_eq!(0_usize, Foo::Bar.into());
assert_eq!(1_usize, Foo::E.into());

Same as:

enum Foo {
    Bar,
    E
}
impl From<Foo> for usize {
    fn from(value: Foo) -> usize {
        Foo as usize
    }
}

lib.rs:

Derive for From and Into usize

use derive_into::ToUsize;
#[derive(ToUsize)]
enum Foo {
   Bar,
   E
}
assert_eq!(0_usize, Foo::Bar.into());
assert_eq!(1_usize, Foo::E.into());

Dependencies

~240–680KB
~16K SLoC