mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-02-07 11:36:14 +02:00
Clarify completion condition for elevator exercise (#1574)
Addresses the first part of #1565.
This commit is contained in:
parent
f04e277744
commit
e765159be1
@ -8,7 +8,17 @@ We will create a data structure to represent an event in an elevator control
|
|||||||
system. It is up to you to define the types and functions to construct various
|
system. It is up to you to define the types and functions to construct various
|
||||||
events. Use `#[derive(Debug)]` to allow the types to be formatted with `{:?}`.
|
events. Use `#[derive(Debug)]` to allow the types to be formatted with `{:?}`.
|
||||||
|
|
||||||
```rust,compile_fail
|
This exercise only requires creating and populating data structures so that
|
||||||
|
`main` runs without errors. The next part of the course will cover getting data
|
||||||
|
out of these structures.
|
||||||
|
|
||||||
|
```rust,should_panic
|
||||||
|
{{#include exercise.rs:event}}
|
||||||
|
// TODO: add required variants
|
||||||
|
}
|
||||||
|
|
||||||
|
{{#include exercise.rs:direction}}
|
||||||
|
|
||||||
{{#include exercise.rs:car_arrived}}
|
{{#include exercise.rs:car_arrived}}
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@ -31,6 +41,3 @@ events. Use `#[derive(Debug)]` to allow the types to be formatted with `{:?}`.
|
|||||||
|
|
||||||
{{#include exercise.rs:main}}
|
{{#include exercise.rs:main}}
|
||||||
```
|
```
|
||||||
|
|
||||||
This exercise only requires creating data structures. The next part of the
|
|
||||||
course will cover getting data out of these structures.
|
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// ANCHOR: solution
|
// ANCHOR: solution
|
||||||
|
// ANCHOR: event
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// An event in the elevator system that the controller must react to.
|
/// An event in the elevator system that the controller must react to.
|
||||||
enum Event {
|
enum Event {
|
||||||
|
// ANCHOR_END: event
|
||||||
/// A button was pressed.
|
/// A button was pressed.
|
||||||
ButtonPressed(Button),
|
ButtonPressed(Button),
|
||||||
|
|
||||||
@ -34,12 +36,14 @@ enum Event {
|
|||||||
/// A floor is represented as an integer.
|
/// A floor is represented as an integer.
|
||||||
type Floor = i32;
|
type Floor = i32;
|
||||||
|
|
||||||
|
// ANCHOR: direction
|
||||||
/// A direction of travel.
|
/// A direction of travel.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Direction {
|
enum Direction {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
}
|
}
|
||||||
|
// ANCHOR_END: direction
|
||||||
|
|
||||||
/// A user-accessible button.
|
/// A user-accessible button.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user