#usize #enums #from #into

macro derive-to-usize

Derive for From and Into usize

1 unstable release

0.1.0 Jun 25, 2024

#18 in #into

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

~225–670KB
~16K SLoC