#enums #variant #quote #macro #methods #generate #unwrap

unwrap-enum

generate methods to access enum variants

2 unstable releases

0.1.0 Jul 22, 2024
0.0.2 May 19, 2024

#1603 in Rust patterns

Download history 111/week @ 2024-07-16 36/week @ 2024-07-23 8/week @ 2024-07-30 8/week @ 2024-09-10 7/week @ 2024-09-17 21/week @ 2024-09-24 11/week @ 2024-10-01

117 downloads per month

GPL-3.0-or-later

15KB

unwrap-enum

A crate to generate methods to unwrap enums as certain variants, like is_none and is_none on Option.

Example

use unwrap_enum::{EnumAs, EnumIs};

#[derive(Clone, Debug, EnumAs, EnumIs)]
enum Value {
    String(String),
    Int(i64)
}

let value = Value::String("hello world".to_string());

assert!(value.is_string());
assert!(!value.is_int());
assert!(matches!(value.as_string(), Some(string) if string == "hello world"));
assert!(matches!(value.as_int(), None));

Todo

Implement EnumAsMut and EnumInto derive macros.


lib.rs:

unwrap-enum

A crate to generate methods to unwrap enums as certain variants, like is_none and is_none on Option.

Example

use unwrap_enum::{EnumAs, EnumIs};

#[derive(Clone, Debug, EnumAs, EnumIs)]
enum Value {
    String(String),
    Int(i64)
}

let value = Value::String("hello world".to_string());

assert!(value.is_string());
assert!(!value.is_int());
assert!(matches!(value.as_string(), Some(string) if string == "hello world"));
assert!(matches!(value.as_int(), None));

Todo

Implement EnumAsMut and EnumInto derive macros.

Dependencies

~0.6–1.1MB
~25K SLoC