Crates.io | enumeration |
lib.rs | enumeration |
version | |
source | src |
created_at | 2022-05-29 09:25:04.478685 |
updated_at | 2024-12-03 06:44:31.113436 |
description | An extension to rust enum |
homepage | https://github.com/feois/rust-enumeration |
repository | https://github.com/feois/rust-enumeration |
max_upload_size | |
id | 596407 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Provides extension to rust enum
This crate provides Enumeration
trait for rust enum
with the following features
Enumeration::VARIANT_COUNT
Enumeration::Index
) and enumerationuse enumeration::{prelude::*, OutOfRangeError};
enumerate!(pub Foo(u8; i32 = 11)
Bar
Baz = 99
);
pub fn main() -> Result<Foo, OutOfRangeError> {
assert_eq!(Foo::Bar, Foo::variant(0)?);
assert_eq!(Foo::Baz.to_index(), 1);
assert_eq!(Foo::Bar.value(), 11);
assert_eq!(Foo::Baz.value(), 99);
let variants: Vec<Variant<_>> = vec![Foo::Bar.into(), SomeOtherExternalEnum::SomeVariant.into()];
assert_eq!(variants[0].cast::<Foo>(), Ok(Foo::Bar));
assert_eq!(variants[1].cast::<SomeOtherExternalEnum>(), Ok(SomeOtherExternalEnum::SomeVariant));
assert!(variants[1].cast::<Foo>().is_err());
}