https://github.com/lpenz/enumchar
Rust derive macro for enums where each variant is represented by a single char
https://github.com/lpenz/enumchar
Last synced: about 1 month ago
JSON representation
Rust derive macro for enums where each variant is represented by a single char
- Host: GitHub
- URL: https://github.com/lpenz/enumchar
- Owner: lpenz
- License: mit
- Created: 2025-01-01T22:19:34.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-06T19:57:31.000Z (4 months ago)
- Last Synced: 2025-03-31T19:02:39.612Z (about 2 months ago)
- Language: Rust
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/lpenz/enumchar/actions/workflows/ci.yml)
[](https://coveralls.io/github/lpenz/enumchar?branch=main)
[](https://deps.rs/repo/github/lpenz/enumchar)
[](https://crates.io/crates/enumchar)# enumchar
*enumchar* is a simple rust derive proc_macro for `enums` where each
variant corresponds to a `char`.Example usage:
```rust
use enumchar::EnumChar;#[derive(EnumChar)]
pub enum Cell {
#[char('#')]
Wall,
#[char('.')]
Empty,
}
```The effect of the code above is the automatic `impl` of `TryFrom`,
`TryInto` and `std::fmt::Display`. It also implements
`Into` if all variants have a corresponding `char`, as we
can't return an error from that one.I've been using this macro to parse all those 2D mazes in
[adventofcode](https://adventofcode.com/) - feel free to use it too.