# enum-values
[](https://gitlab.com/wiktor/enum-values/badges/main/pipeline.svg)
[](https://crates.io/crates/enum-values)
`EnumValues` works with a specific subset of enums: these that have primitive discriminants.
The guiding use case was automatic generation of exit codes documentation from `Error` enums.
```rust
use enum_values::EnumValues;
/// Mapping for relevant [`Error`] variants to an [`std::process::ExitCode`].
#[derive(EnumValues, Debug)]
#[repr(u8)]
pub enum Error {
/// IO error.
Io(std::io::Error) = 2,
/// Fmt error.
Fmt(std::fmt::Error) = 3,
}
let variants = Error::variants().collect::<Vec<_>>();
eprintln!("Variants: {variants:#?}",);
assert_eq!(variants.len(), 2);
assert_eq!("IO error.", variants[0].doc);
assert_eq!("Io", variants[0].name);
assert_eq!(2, variants[0].value);
assert_eq!("Fmt error.", variants[1].doc);
assert_eq!("Fmt", variants[1].name);
assert_eq!(3, variants[1].value);
```
## License
This project is licensed under either of:
- [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0),
- [MIT license](https://opensource.org/licenses/MIT).
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.