enumchar

Crates.ioenumchar
lib.rsenumchar
version0.1.2
created_at2025-01-01 23:05:52.880895+00
updated_at2025-01-06 20:00:30.166272+00
descriptionRust derive macro for enums where each variant is represented by a single char
homepagehttps://github.com/lpenz/enumchar
repositoryhttps://github.com/lpenz/enumchar
max_upload_size
id1501124
size19,602
Leandro Lisboa Penz (lpenz)

documentation

README

CI coveralls dependency status crates.io

enumchar

enumchar is a simple rust derive proc_macro for enums where each variant corresponds to a char.

Example usage:

use enumchar::EnumChar;

#[derive(EnumChar)]
pub enum Cell {
    #[char('#')]
    Wall,
    #[char('.')]
    Empty,
}

The effect of the code above is the automatic impl of TryFrom<char>, TryInto<char> and std::fmt::Display. It also implements Into<char> 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 - feel free to use it too.

Commit count: 15

cargo fmt