use std::f64::consts::PI;
use quick_impl::quick_impl;
#[quick_impl]
pub enum Shape {
#[quick_impl(pub const is, pub inspect, impl Default)]
Circle(f64),
#[quick_impl(pub as_ref, as_ref_mut, pub set, impl From)]
Rectangle(f64, f64),
#[quick_impl(pub as_ref, as_ref_mut, pub into)]
Square(f64),
#[quick_impl(pub const from = "create_cuboid", pub const is, pub into)]
Cuboid { width: f64, height: f64, depth: f64 },
}
fn main() {
let circle = Shape::Circle(5.0);
assert!(circle.is_circle());
let circle = Shape::Circle(PI).inspect_circle(|r| {
assert_eq!(*r, PI);
});
assert!(circle.is_circle());
let default_circle = Shape::default();
assert!(default_circle.is_circle());
let rectangle = Shape::from((3.0, 4.0));
assert_eq!(rectangle.as_rectangle().unwrap(), (&3.0, &4.0));
let mut square = Shape::Square(10.0);
*square.as_square_mut().unwrap() = 15.0;
assert_eq!(*square.as_square().unwrap(), 15.0);
assert_eq!(square.into_square().unwrap(), 15.0);
let mut shape = Shape::Circle(1.0);
let previous = shape.set_rectangle(5.0, 6.0);
assert!(previous.is_circle());
assert_eq!(shape.as_rectangle().unwrap(), (&5.0, &6.0));
let cuboid = Shape::create_cuboid(2.0, 3.0, 4.0);
assert!(cuboid.is_cuboid());
let (width, height, depth) = cuboid.into_cuboid().unwrap();
assert_eq!((width, height, depth), (2.0, 3.0, 4.0));
}