Macro library for use in generating From & TryFrom implementations for enums composed of unnamed single members.
In other terms, of the following format.
rust
pub enum Variants {
Integer(i32),
Float(f32),
Bool(bool),
Byte(u8),
}
This library has 2 macros, TryFromVariants & FromVariants.
TryFromVariants implements TryFrom for each of the variant types, permitting code such as, ```rust use enumvariantmacros::*; use std::error::Error; use strum_macros::IntoStaticStr;
enum Variants { Integer(i32), Float(f32), }
fn main() -> Result<(), Box
Note: Derivation of this type also requires that
impl From
FromVariants is relatively simple, it just generates From for each wrapped type. ```rust use enumvariantmacros::*;
enum Variants { Integer(i32), Float(f32), }
let variant = Variants::from(12); assert_eq!(Variants::Integer(12), variant); ```
If this library is not to your preference, may I recomend [enum dispatch], a more expansive library that also provides from & try_into for enums.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.