Skip to content

Commit d459912

Browse files
committed
*scope
1 parent d5c1d37 commit d459912

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

rust/src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,17 @@ fn mutable_function_argument() {
276276
let mut a = String::from("a");
277277
fn append(arg: &mut String, s: &str) {
278278
arg.push_str(s);
279-
// immutable: arg += 1;
280-
//arg + 1 // last value is return value
281279
}
282280
append(&mut a, "b");
283281
append(&mut a, "c");
284282
assert_eq!(a, "abc");
283+
let b = a;
284+
// a is undefined
285+
let c = b + "d"; // content of b is moved here
286+
// b is unusable here
287+
assert_eq!(c, "abcd");
288+
a = c; // reusing a, because it is mutconstantsable
289+
assert_eq!(a, "abcd");
285290
}
286291

287292
#[test]

0 commit comments

Comments
 (0)