تمرین: رویدادهای آسانسور
ما یک ساختار داده برای نمایش یک رویداد در یک سیستم کنترل آسانسور ایجاد خواهیم کرد. این به شما بستگی دارد که انواع و عملکردها را برای ساخت رویدادهای مختلف تعریف کنید. از #[derive(Debug)] استفاده کنید تا اجازه دهید انواع با {:?} قالببندی شوند.
این تمرین فقط به ایجاد و پر کردن ساختارهای داده نیاز دارد تا main بدون خطا اجرا شود. بخش بعدی این دوره دریافت دادهها از این ساختارها را پوشش میدهد.
#[derive(Debug)]
/// An event in the elevator system that the controller must react to.
enum Event {
// TODO: add required variants
}
/// A direction of travel.
#[derive(Debug)]
enum Direction {
Up,
Down,
}
/// The car has arrived on the given floor.
fn car_arrived(floor: i32) -> Event {
todo!()
}
/// The car doors have opened.
fn car_door_opened() -> Event {
todo!()
}
/// The car doors have closed.
fn car_door_closed() -> Event {
todo!()
}
/// A directional button was pressed in an elevator lobby on the given floor.
fn lobby_call_button_pressed(floor: i32, dir: Direction) -> Event {
todo!()
}
/// A floor button was pressed in the elevator car.
fn car_floor_button_pressed(floor: i32) -> Event {
todo!()
}
fn main() {
println!(
"A ground floor passenger has pressed the up button: {:?}",
lobby_call_button_pressed(0, Direction::Up)
);
println!("ماشین به طبقه همکف رسیده است: {:?}", car_arrived(0));
println!("در ماشین باز شد: {:?}", car_door_opened());
println!(
"یک مسافر دکمه طبقه 3 را فشار داده است: {:?}",
car_floor_button_pressed(3)
);
println!("در ماشین بسته شد: {:?}", car_door_closed());
println!("ماشین به طبقه ۳ رسیده است: {:?}", car_arrived(3));
}