Lymia / enumset

A library for compact bit sets containing enums.
Apache License 2.0
91 stars 35 forks source link

add a blanket implementation of Display for EnumSet<T> when T implements Display #46

Closed tsheinen closed 1 year ago

tsheinen commented 1 year ago

I wanted this for myself and I think this display impl is general enough to be useful built-in?

#[derive(EnumSetType, Debug)]
pub enum DisplayEnum {
    A, B, C, D
}

impl core::fmt::Display for DisplayEnum {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", match self {
            DisplayEnum::A => "A",
            DisplayEnum::B => "B",
            DisplayEnum::C => "C",
            DisplayEnum::D => "D",
        })?;
        Ok(())
    }
}

#[test]
fn test_display() {
let target = DisplayEnum::A | DisplayEnum::B | DisplayEnum::D;
    assert_eq!(format!("{}", target), "(A | B | D)");
}
Lymia commented 1 year ago

I will implement this, but am rejecting the pull request.