macro_rules! closed_enum {
(
$(#[$meta:meta])*
$vis:vis enum $name:ident {
$( $(#[$vmeta:meta])* $variant:ident => $text:literal ),+ $(,)?
}
) => {
$(#[$meta])*
$vis enum $name {
$( $(#[$vmeta])* $variant ),+
}
impl $name {
pub const ALL: &'static [Self] = &[ $( Self::$variant ),+ ];
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
$( Self::$variant => $text ),+
}
}
}
impl ::std::fmt::Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.write_str(self.as_str())
}
}
};
}
pub(crate) use closed_enum;