#enums #helper #checking #readability #macro #u32 #derive

macro enum_helpers

Adds functions like is_, as_, as_mut_ and into_ to enums

4 releases

0.0.4 Jun 19, 2023
0.0.3 Jun 18, 2023
0.0.2 Jun 18, 2023
0.0.1 Jun 16, 2023

#599 in Procedural macros

Download history 16/week @ 2024-02-26 1/week @ 2024-03-11 68/week @ 2024-04-01

69 downloads per month

MIT license

14KB
248 lines

enum_helpers

github crates.io docs.rs

A Rust library to add helper functions to enums, with methods such as is_, as_, as_mut_, and into_, allowing you to simply your codebase and improve code readability.

Example Usage

The following example demonstrates the usage of the EnumIs derive macro to utilize a simpler type checking for enums.

use enum_helpers::EnumIs;

#[derive(EnumIs)]
pub enum Test {
    Example(u32),
}

pub fn main() {
    let test = Test::Example(123);
    assert!(test.is_example()); // true
}

Additional Resources

For more examples, refer to the tests directory.

To keep up with the latest features, improvements, and bug fixes, refer to the Changelog file.

Dependencies

~0.9–1.4MB
~26K SLoC