Skip to content

Commit 7274f1d

Browse files
committed
chore: Refactored to adhere to new rustlings version
1 parent 1c27aee commit 7274f1d

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

exercises/06_move_semantics/move_semantics6.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616

1717
let mut increment = || {
1818
counter += 1;
19-
println!("counter: {}", counter);
19+
println!("counter equals {}", counter);
2020
};
2121

2222
increment();

rustlings-macros/info.toml

+7-10
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ There are two solutions:
189189

190190
[[exercises]]
191191
name = "functions6"
192-
path = "exercises/02_functions/functions6.rs"
192+
dir = "02_functions"
193193
mode = "compile"
194194
hint = """
195195
Hint FIX #1: Closures can capture variables defined in the outer context.
@@ -199,8 +199,7 @@ specified in the signature. But the closure cannot be reused with different
199199
input types.
200200
201201
Read more about closures in the rust book dedicated section:
202-
https://doc.rust-lang.org/book/ch13-01-closures.html
203-
"""
202+
https://doc.rust-lang.org/book/ch13-01-closures.html"""
204203

205204
# IF
206205

@@ -408,17 +407,15 @@ to be adjusted."""
408407

409408
[[exercises]]
410409
name = "move_semantics6"
411-
path = "exercises/06_move_semantics/move_semantics6.rs"
410+
dir = "06_move_semantics"
412411
mode = "compile"
413412
hint = """
414-
When a closure capture a variable to modify it, it borrows that variable as a
415-
mutable reference. In this exercise, as the closure mutably borrows `counter`
416-
and is called later, any attempt to reborrow `counter` in between will lead to
417-
an error.
413+
When a closure captures a variable to modify it, it actually borrows that variable
414+
as a mutable reference. In this exercise, the closure mutably borrows the `counter`
415+
variable, thus, any attempt to borrow `counter` between closure calls leads to an error.
418416
419417
You cannot immutably borrow a variable if a mutable closure is
420-
called later in the scope.
421-
"""
418+
called later in the scope."""
422419

423420
# STRUCTS
424421

solutions/02_functions/functions6.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let outer_var = 1;
3+
let closure_1 = |input_var: u32| -> u32 {input_var + outer_var};
4+
println!("Closure#1 returns {}", closure_1(5));
5+
6+
let closure_2 = |input_var| println!("Closure#2 (input_var {})", input_var);
7+
closure_2(2);
8+
closure_2(5);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn main() {
2+
let mut counter = 0;
3+
4+
let mut increment = || {
5+
counter += 1;
6+
println!("counter equals {}", counter);
7+
};
8+
9+
increment();
10+
increment();
11+
let _reborrowed_counter = &counter;
12+
13+
assert_eq!(counter, 2);
14+
}

0 commit comments

Comments
 (0)