Skip to content

Commit f6a411e

Browse files
committed
update
1 parent 2f2152a commit f6a411e

File tree

22 files changed

+115
-66
lines changed

22 files changed

+115
-66
lines changed

.rustlings-state.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DON'T EDIT THIS FILE!
2+
3+
intro2

exercises/enums/enums1.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
//
33
// No hints this time! ;)
44

5-
// I AM NOT DONE
65

76
#[derive(Debug)]
87
enum Message {
9-
// TODO: define a few types of messages as used below
8+
Quit,
9+
Echo,
10+
Move,
11+
ChangeColor,
1012
}
1113

1214
fn main() {

exercises/enums/enums2.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
76

87
#[derive(Debug)]
98
enum Message {
10-
// TODO: define the different variants used below
9+
Move{x: i32, y: i32},
10+
Echo(String),
11+
ChangeColor(i32, i32, i32),
12+
Quit,
1113
}
1214

1315
impl Message {

exercises/enums/enums3.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
66
// hint.
77

8-
// I AM NOT DONE
98

109
enum Message {
11-
// TODO: implement the message variant types based on their usage below
10+
ChangeColor(u8, u8, u8),
11+
Echo(String),
12+
Quit,
13+
Move(Point),
1214
}
1315

1416
struct Point {
@@ -43,6 +45,20 @@ impl State {
4345
// variants
4446
// Remember: When passing a tuple as a function argument, you'll need
4547
// extra parentheses: fn function((t, u, p, l, e))
48+
match message {
49+
Message::ChangeColor(x, y, z) => {
50+
self.change_color((x, y, z));
51+
},
52+
Message::Echo(s) => {
53+
self.echo(s);
54+
},
55+
Message::Move(p) => {
56+
self.move_position(p);
57+
},
58+
Message::Quit => {
59+
self.quit();
60+
}
61+
}
4662
}
4763
}
4864

exercises/hashmaps/hashmaps1.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
// Execute `rustlings hint hashmaps1` or use the `hint` watch subcommand for a
1212
// hint.
1313

14-
// I AM NOT DONE
1514

1615
use std::collections::HashMap;
1716

1817
fn fruit_basket() -> HashMap<String, u32> {
19-
let mut basket = // TODO: declare your hash map here.
18+
let mut basket = HashMap::new();
2019

2120
// Two bananas are already given for you :)
2221
basket.insert(String::from("banana"), 2);
2322

2423
// TODO: Put more fruits in your basket here.
24+
basket.insert(String::from("apple"), 5);
25+
basket.insert(String::from("peach"), 11);
2526

2627
basket
2728
}

exercises/hashmaps/hashmaps2.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a
1515
// hint.
1616

17-
// I AM NOT DONE
17+
1818

1919
use std::collections::HashMap;
2020

@@ -37,9 +37,12 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
3737
];
3838

3939
for fruit in fruit_kinds {
40-
// TODO: Insert new fruits if they are not already present in the
41-
// basket. Note that you are not allowed to put any type of fruit that's
42-
// already present!
40+
match fruit {
41+
Fruit::Apple => basket.entry(Fruit::Apple).or_insert(4),
42+
Fruit::Banana => basket.entry(Fruit::Banana).or_insert(2),
43+
Fruit::Mango => basket.entry(Fruit::Mango).or_insert(5),
44+
other => basket.entry(other).or_insert(6)
45+
};
4346
}
4447
}
4548

exercises/hashmaps/hashmaps3.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Execute `rustlings hint hashmaps3` or use the `hint` watch subcommand for a
1515
// hint.
1616

17-
// I AM NOT DONE
17+
1818

1919
use std::collections::HashMap;
2020

@@ -34,7 +34,13 @@ fn build_scores_table(results: String) -> HashMap<String, Team> {
3434
let team_1_score: u8 = v[2].parse().unwrap();
3535
let team_2_name = v[1].to_string();
3636
let team_2_score: u8 = v[3].parse().unwrap();
37-
// TODO: Populate the scores table with details extracted from the
37+
let t = scores.entry(team_1_name).or_insert(Team{goals_scored: 0, goals_conceded: 0});
38+
t.goals_scored += team_1_score;
39+
t.goals_conceded += team_2_score;
40+
let t = scores.entry(team_2_name).or_insert(Team{goals_scored: 0, goals_conceded: 0});
41+
t.goals_scored += team_2_score;
42+
t.goals_conceded += team_1_score;
43+
3844
// current line. Keep in mind that goals scored by team_1
3945
// will be the number of goals conceded from team_2, and similarly
4046
// goals scored by team_2 will be the number of goals conceded by

exercises/modules/modules1.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
// Execute `rustlings hint modules1` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
76

87
mod sausage_factory {
98
// Don't let anybody outside of this module see this!
109
fn get_secret_recipe() -> String {
1110
String::from("Ginger")
1211
}
1312

14-
fn make_sausage() {
13+
pub fn make_sausage() {
1514
get_secret_recipe();
1615
println!("sausage!");
1716
}

exercises/modules/modules2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// Execute `rustlings hint modules2` or use the `hint` watch subcommand for a
88
// hint.
99

10-
// I AM NOT DONE
10+
1111

1212
mod delicious_snacks {
1313
// TODO: Fix these use statements
14-
use self::fruits::PEAR as ???
15-
use self::veggies::CUCUMBER as ???
14+
pub use self::fruits::PEAR as fruit;
15+
pub use self::veggies::CUCUMBER as veggie;
1616

1717
mod fruits {
1818
pub const PEAR: &'static str = "Pear";

exercises/modules/modules3.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
// Execute `rustlings hint modules3` or use the `hint` watch subcommand for a
99
// hint.
1010

11-
// I AM NOT DONE
1211

1312
// TODO: Complete this use statement
14-
use ???
13+
use std::time::{SystemTime, UNIX_EPOCH};
1514

1615
fn main() {
1716
match SystemTime::now().duration_since(UNIX_EPOCH) {

0 commit comments

Comments
 (0)