#enums #parse #char

macro enumchar

Rust derive macro for enums where each variant is represented by a single char

3 releases

new 0.1.2 Jan 6, 2025
0.1.1 Jan 5, 2025
0.1.0 Jan 1, 2025

#131 in Parser tooling

Download history 345/week @ 2025-01-01

345 downloads per month

MIT license

12KB
228 lines

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.

Dependencies

~215–650KB
~16K SLoC