#![allow(dead_code)]
use enumeraties::props;
use enumeraties::EnumProp;
struct ShapeDef {
name: &'static str,
vertices: u32,
}
fn print_shape<E>(e: E)
where
E: EnumProp<ShapeDef>,
{
println!(
"A {} has {} vertices",
e.property().name,
e.property().vertices
)
}
enum PlanarShape {
Triangle,
Square,
Hexagon,
}
props! {
impl Deref for PlanarShape as const ShapeDef {
Self::Triangle => {
name: "Triangle",
vertices: 3,
}
Self::Square => {
name: "Square",
vertices: 4,
}
Self::Hexagon => {
name: "Hexagon",
vertices: 6,
}
}
}
enum Solid {
Tetrahedron,
Cube,
Icosahedron,
}
props! {
impl Deref for Solid as const ShapeDef {
Self::Tetrahedron => {
name: "Tetrahedron",
vertices: 4,
}
Self::Cube => {
name: "Cube",
vertices: 8,
}
Self::Icosahedron => {
name: "Icosahedron",
vertices: 12,
}
}
}
pub fn main() {
print_shape(PlanarShape::Triangle);
print_shape(Solid::Icosahedron);
}