An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

[![CI](https://github.com/lpenz/enumchar/actions/workflows/ci.yml/badge.svg)](https://github.com/lpenz/enumchar/actions/workflows/ci.yml)
[![coveralls](https://coveralls.io/repos/github/lpenz/enumchar/badge.svg?branch=main)](https://coveralls.io/github/lpenz/enumchar?branch=main)
[![dependency status](https://deps.rs/repo/github/lpenz/enumchar/status.svg)](https://deps.rs/repo/github/lpenz/enumchar)
[![crates.io](https://img.shields.io/crates/v/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.