Compare commits

...

4 commits

Author SHA1 Message Date
Matthias effd88593c
Merge 77b687d501 into 42b5c0a1f7 2024-06-24 13:06:52 +02:00
Mo 42b5c0a1f7
Merge pull request #1997 from jphilis/main
chore: update error message to error message given by rustc (error[E0596]) in hint
2024-06-21 17:11:48 +02:00
jphilis 1ede3a82e9
chore: update error message to error message given by rustc. error[E0596] 2024-06-19 14:55:34 +02:00
Matthias Richter 77b687d501 fix(enums) make enum variants more consistent
closes #1545
2023-11-14 08:19:40 +01:00
4 changed files with 23 additions and 3 deletions

View file

@ -12,6 +12,7 @@ enum Message {
fn main() {
println!("{:?}", Message::Quit);
println!("{:?}", Message::Echo);
println!("{:?}", Message::Resize);
println!("{:?}", Message::Move);
println!("{:?}", Message::ChangeColor);
}

View file

@ -10,6 +10,12 @@ enum Message {
// TODO: define the different variants used below
}
#[derive(Debug)]
struct Point {
x: u8,
y: u8,
}
impl Message {
fn call(&self) {
println!("{:?}", self);
@ -18,7 +24,8 @@ impl Message {
fn main() {
let messages = [
Message::Move { x: 10, y: 30 },
Message::Resize { w: 10, h: 30 },
Message::Move(Point { x: 10, y: 15 }),
Message::Echo(String::from("hello world")),
Message::ChangeColor(200, 255, 255),
Message::Quit,

View file

@ -18,6 +18,8 @@ struct Point {
struct State {
color: (u8, u8, u8),
width: u8,
height: u8,
position: Point,
quit: bool,
message: String,
@ -36,6 +38,11 @@ impl State {
self.message = s
}
fn resize(&mut self, w: u8, h: u8) {
self.width = w;
self.height = h;
}
fn move_position(&mut self, p: Point) {
self.position = p;
}
@ -55,16 +62,21 @@ mod tests {
fn test_match_message_call() {
let mut state = State {
quit: false,
width: 0,
height: 0,
position: Point { x: 0, y: 0 },
color: (0, 0, 0),
message: "hello world".to_string(),
};
state.process(Message::ChangeColor(255, 0, 255));
state.process(Message::Echo(String::from("Hello world!")));
state.process(Message::Resize { w: 10, h: 30 });
state.process(Message::Move(Point { x: 10, y: 15 }));
state.process(Message::Quit);
assert_eq!(state.color, (255, 0, 255));
assert_eq!(state.width, 10);
assert_eq!(state.height, 30);
assert_eq!(state.position.x, 10);
assert_eq!(state.position.y, 15);
assert_eq!(state.quit, true);

View file

@ -318,7 +318,7 @@ name = "move_semantics1"
path = "exercises/06_move_semantics/move_semantics1.rs"
mode = "test"
hint = """
So you've got the "cannot borrow immutable local variable `vec` as mutable"
So you've got the "cannot borrow `vec` as mutable, as it is not declared as mutable"
error on the line where we push an element to the vector, right?
The fix for this is going to be adding one keyword, and the addition is NOT on
@ -465,7 +465,7 @@ path = "exercises/08_enums/enums2.rs"
mode = "compile"
hint = """
You can create enumerations that have different variants with different types
such as no data, anonymous structs, a single string, tuples, ...etc"""
such as anonymous structs, structs, a single string, tuples, no data, ...etc"""
[[exercises]]
name = "enums3"