use hotdrink_rs::{model::Component, component, ret};
pub fn main() {
let mut my_component: Component<i32> = component! {
component MyComponent {
let height: i32 = 0, width: i32 = 0,
area: i32 = 0, perimeter: i32 = 0;
constraint HeightTimesWidthEqualsArea {
hwa(height: &i32, width: &i32) -> [area] = ret![*height * *width];
haw(height: &i32, area: &i32) -> [width] = ret![*area / *height];
wah(width: &i32, area: &i32) -> [height] = ret![*area / *width];
}
constraint TwoHeightPlusTwoWidthEqualsPerimeter {
hwp(height: &i32, width: &i32) -> [perimeter] = ret![2 * *height + 2 * *width];
hpw(height: &i32, perimeter: &i32) -> [width] = ret![*perimeter - 2 * *height];
wph(width: &i32, perimeter: &i32) -> [height] = ret![*perimeter - 2 * *width];
}
}
};
my_component.subscribe("height", |e| { println!("height: {:?}", e); }).unwrap();
my_component.subscribe("width", |e| { println!("width: {:?}", e); }).unwrap();
my_component.subscribe("area", |e| { println!("area: {:?}", e); }).unwrap();
my_component.subscribe("perimeter", |e| { println!("perimeter: {:?}", e); }).unwrap();
my_component.set_variable("height", 3).unwrap();
my_component.set_variable("width", 5).unwrap();
my_component.update().unwrap();
}