#enums #helper #readability #checking #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

#1853 in Procedural macros

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.6–1.1MB
~22K SLoC