summaryrefslogtreecommitdiff
path: root/old_curriculum/move_semantics/move_semantics1.rs
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-04-26 21:29:11 +0200
committerolivia <olivia@fastmail.com>2018-04-26 21:29:11 +0200
commit5e89d1e888a8fafc39096afce36d02e313f349c2 (patch)
tree97b13f8223012d1db88d510cd79ea0e49570d1f7 /old_curriculum/move_semantics/move_semantics1.rs
parent32ac403da5c49b002ba420186d3122501196ff89 (diff)
move old files to a separate directory
Diffstat (limited to 'old_curriculum/move_semantics/move_semantics1.rs')
-rw-r--r--old_curriculum/move_semantics/move_semantics1.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/old_curriculum/move_semantics/move_semantics1.rs b/old_curriculum/move_semantics/move_semantics1.rs
new file mode 100644
index 0000000..73dc0ab
--- /dev/null
+++ b/old_curriculum/move_semantics/move_semantics1.rs
@@ -0,0 +1,43 @@
+// move_semantics1.rs
+// Make me compile! Scroll down for hints :)
+
+pub fn main() {
+ let vec0 = Vec::new();
+
+ let vec1 = fill_vec(vec0);
+
+ println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
+
+ vec1.push(88);
+
+ println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
+
+}
+
+fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
+ let mut vec = vec;
+
+ vec.push(22);
+ vec.push(44);
+ vec.push(66);
+
+ vec
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on line 11,
+// right? The fix for this is going to be adding one keyword, and the addition is NOT on line 11
+// where the error is.