mirror of
https://github.com/notohh/rustlings.git
synced 2025-09-16 11:03:15 -04:00
Merge remote-tracking branch 'upstream/main' into fix-enum-variant-inconsistency
This commit is contained in:
commit
7123c7ae3a
269 changed files with 9826 additions and 7926 deletions
|
@ -1,12 +1,6 @@
|
|||
// enums1.rs
|
||||
//
|
||||
// No hints this time! ;)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
// TODO: define a few types of messages as used below
|
||||
// TODO: Define a few types of messages as used below.
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
// enums2.rs
|
||||
//
|
||||
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
// TODO: define the different variants used below
|
||||
// TODO: Define the different variants used below.
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -18,7 +12,7 @@ struct Point {
|
|||
|
||||
impl Message {
|
||||
fn call(&self) {
|
||||
println!("{:?}", self);
|
||||
println!("{self:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
// enums3.rs
|
||||
//
|
||||
// Address all the TODOs to make the tests pass!
|
||||
//
|
||||
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
enum Message {
|
||||
// TODO: implement the message variant types based on their usage below
|
||||
// TODO: Implement the message variant types based on their usage below.
|
||||
}
|
||||
|
||||
struct Point {
|
||||
|
@ -35,25 +26,29 @@ impl State {
|
|||
}
|
||||
|
||||
fn echo(&mut self, s: String) {
|
||||
self.message = s
|
||||
self.message = s;
|
||||
}
|
||||
|
||||
fn resize(&mut self, w: u8, h: u8) {
|
||||
self.width = w;
|
||||
self.height = h;
|
||||
fn resize(&mut self, width: u8, height: u8) {
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
}
|
||||
|
||||
fn move_position(&mut self, p: Point) {
|
||||
self.position = p;
|
||||
fn move_position(&mut self, point: Point) {
|
||||
self.position = point;
|
||||
}
|
||||
|
||||
fn process(&mut self, message: Message) {
|
||||
// TODO: create a match expression to process the different message variants
|
||||
// TODO: Create a match expression to process the different message variants.
|
||||
// Remember: When passing a tuple as a function argument, you'll need extra parentheses:
|
||||
// fn function((t, u, p, l, e))
|
||||
// e.g. `foo((t, u, p, l, e))`
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -66,8 +61,9 @@ mod tests {
|
|||
height: 0,
|
||||
position: Point { x: 0, y: 0 },
|
||||
color: (0, 0, 0),
|
||||
message: "hello world".to_string(),
|
||||
message: String::from("hello world"),
|
||||
};
|
||||
|
||||
state.process(Message::ChangeColor(255, 0, 255));
|
||||
state.process(Message::Echo(String::from("Hello world!")));
|
||||
state.process(Message::Resize { w: 10, h: 30 });
|
||||
|
@ -79,7 +75,7 @@ mod tests {
|
|||
assert_eq!(state.height, 30);
|
||||
assert_eq!(state.position.x, 10);
|
||||
assert_eq!(state.position.y, 15);
|
||||
assert_eq!(state.quit, true);
|
||||
assert!(state.quit);
|
||||
assert_eq!(state.message, "Hello world!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue