#![allow(dead_code)]
use enum_map::enum_map;
use enum_map::Enum;
use enum_map::EnumMap;
use enum_properties::enum_properties;
use enumeraties::props;
struct ShapeDef {
name: &'static str,
vertices: usize,
internal_angle: f32,
}
enum_properties! {
#[derive(Enum)]
enum Shape: ShapeDef {
Triangle {
name: "Triangle",
vertices: 3,
internal_angle: core::f32::consts::PI / 3.,
},
Square {
name: "Square",
vertices: 4,
internal_angle: core::f32::consts::PI / 4.,
},
Hexagon {
name: "Hexagon",
vertices: 6,
internal_angle: core::f32::consts::PI / 6.,
},
}
}
struct LazyProps {
description: String,
area_ration_with: EnumMap<Shape, f32>,
}
props! {
impl Shape : fn props as lazy LazyProps {
Self::Triangle => {
description: [1,2,3].iter().map(ToString::to_string).collect(),
area_ration_with: enum_map! {
Shape::Triangle => 1.0,
Shape::Square => 3_f32.sqrt() / 4_f32,
Shape::Hexagon => 1.0 / 6.0,
},
}
Self::Square => {
description: String::new(),
area_ration_with: enum_map! {
Shape::Triangle => 1.0,
Shape::Square => 4_f32 / 3_f32.sqrt(),
Shape::Hexagon => 2_f32 / (3_f32 * 3_f32.sqrt()),
},
}
Self::Hexagon => {
description: {
let mut buf = String::new();
buf .push_str("stuff");
buf
},
area_ration_with: enum_map! {
Shape::Triangle => 6.0,
Shape::Square => 3_f32 * 3_f32.sqrt() / 2_f32,
Shape::Hexagon => 1.0,
},
}
}
}
pub fn main() {
println!(
"A {} has {} vertices and an internal angle of {:.3} radian.",
Shape::Hexagon.name, Shape::Hexagon.vertices, Shape::Hexagon.internal_angle );
println!(
"A Hexagon has {:.3} more area than a Square.",
Shape::Hexagon.props().area_ration_with[Shape::Square]
);
}