A deriving proc-macro for generating functions to automatically give access to the inner members of enum.
The basic case is meant for single item enums, like:
```rust use enumasinner::EnumAsInner;
enum OneEnum { One(u32), } ```
where the inner item can be retrieved with the as_*()
/as_*_mut()
or with the into_*()
functions:
```rust let one = OneEnum::One(1);
asserteq!(*one.asone().unwrap(), 1); asserteq!(one.intoone().unwrap(), 1);
let mut one = OneEnum::One(2);
asserteq!(*one.asone().unwrap(), 1); asserteq!(*one.asonemut().unwrap(), 1); asserteq!(one.into_one().unwrap(), 1); ```
where the result is either a reference for inner items or a tuple containing the inner items.
This will return true if enum's variant matches the expected type
```rust use enumasinner::EnumAsInner;
enum UnitVariants { Zero, One, Two, }
let unit = UnitVariants::Two;
assert!(unit.is_two()); ```
This will return a tuple of the inner types:
```rust use enumasinner::EnumAsInner;
enum ManyVariants { One(u32), Two(u32, i32), Three(bool, u32, i64), } ```
And can be accessed like:
```rust let mut many = ManyVariants::Three(true, 1, 2);
asserteq!(many.asthree().unwrap(), (&true, &1u32, &2i64)); asserteq!(many.asthreemut().unwrap(), (&mut true, &mut 1u32, &mut 2i64)); asserteq!(many.intothree().unwrap(), (true, 1u32, 2_i64)); ```
This will return a tuple of the inner types, like the unnamed option:
```rust use enumasinner::EnumAsInner;
enum ManyVariants { One{ one: u32 }, Two{ one: u32, two: i32 }, Three{ one: bool, two: u32, three: i64 }, } ```
And can be accessed like:
```rust let mut many = ManyVariants::Three{ one: true, two: 1, three: 2 };
asserteq!(many.asthree().unwrap(), (&true, &1u32, &2i64)); asserteq!(many.asthreemut().unwrap(), (&mut true, &mut 1u32, &mut 2i64)); asserteq!(many.intothree().unwrap(), (true, 1u32, 2_i64)); ```