Skip to content

Commit 399ab32

Browse files
feat: Add move_semantics5 exercise. (#746)
* feat: Add move_semantics5 exercise. * feat: Add option3 exercise * Address review comments. Fix typos, sentence formatting. * Remove unwanted newline. * Address review comments: make comment inline, fix format in print.
1 parent 809ec2c commit 399ab32

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// move_semantics5.rs
2+
// Make me compile without adding any newlines or removing any of the lines.
3+
// Execute `rustlings hint move_semantics5` for hints :)
4+
5+
// I AM NOT DONE
6+
7+
fn main() {
8+
let mut x = 100;
9+
let y = &mut x;
10+
let z = &mut *y;
11+
*y += 100;
12+
*z += 1000;
13+
assert_eq!(x, 1200);
14+
}

exercises/option/option3.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// option3.rs
2+
// Make me compile! Execute `rustlings hint option3` for hints
3+
4+
// I AM NOT DONE
5+
6+
struct Point {
7+
x: i32,
8+
y: i32,
9+
}
10+
11+
fn main() {
12+
let y: Option<Point> = Some(Point { x: 100, y: 200 });
13+
14+
match y {
15+
Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y),
16+
_ => println!("no match"),
17+
}
18+
y; // Fix without deleting this line.
19+
}

info.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ So the end goal is to:
210210
- since we're not creating a new vec in `main` anymore, we need to create
211211
a new vec in `fill_vec`, similarly to the way we did in `main`"""
212212

213+
[[exercises]]
214+
name = "move_semantics5"
215+
path = "exercises/move_semantics/move_semantics5.rs"
216+
mode = "compile"
217+
hint = """
218+
Carefully reason about the range in which each mutable reference is in
219+
vogue. Does updating the value of referrent (x) immediately after the
220+
mutable reference is taken helps? Read more about 'Mutable Referenes'
221+
in the book's section References and Borrowing':
222+
https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references."""
223+
213224
# PRIMITIVE TYPES
214225

215226
[[exercises]]
@@ -578,6 +589,16 @@ For example: Some(Some(variable)) = variable2
578589
Also see Option::flatten
579590
"""
580591

592+
[[exercises]]
593+
name = "option3"
594+
path = "exercises/option/option3.rs"
595+
mode = "compile"
596+
hint = """
597+
The compiler says a partial move happened in the `match`
598+
statement. How can this be avoided? The compiler shows the correction
599+
needed. After making the correction as suggested by the compiler, do
600+
read: https://doc.rust-lang.org/std/keyword.ref.html"""
601+
581602
[[exercises]]
582603
name = "result1"
583604
path = "exercises/error_handling/result1.rs"

0 commit comments

Comments
 (0)