Skip to content

Enhance your Rust enums with unit-enum: a procedural macro crate for effortlessly deriving ordinal methods and more for unit-like enums

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

tylium/unit-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnitEnum

The unit-enum crate introduces a procedural macro UnitEnum for Rust developers working with enums that consist entirely of unit variants. This macro enhances such enums by automatically implementing methods to manage enum variants more effectively, promoting ease of use and reducing boilerplate code.

Features

  • Ordinal Methods: Easily obtain the ordinal of an enum variant or convert an ordinal value back to a corresponding enum variant.
  • Variant Count: Retrieve the total number of variants in an enum.

Installation

To use unit-enum in your project, add it as a dependency in your Cargo.toml:

[dependencies]
unit-enum = "1.0.0"

Quick Start

use unit_enum::UnitEnum;

#[derive(UnitEnum)]
enum Color {
    Red,
    Green,
    Blue,
}

let green = Color::Green;
assert_eq!(green.ordinal(), 1);
assert_eq!(Color::from_ordinal(1), Some(Color::Green));
assert_eq!(Color::len(), 3);

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues on our GitHub repository.

License

This project is licensed under either of MIT or Apache-2.0, at your choice.

About

Enhance your Rust enums with unit-enum: a procedural macro crate for effortlessly deriving ordinal methods and more for unit-like enums

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages