summaryrefslogtreecommitdiff
path: root/exercises/move_semantics/move_semantics1.rs
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-11-09 20:31:14 +0100
committerolivia <olivia@fastmail.com>2018-11-09 20:31:14 +0100
commitf7846af7ac388652a6f80a2bbce926ba8f053062 (patch)
tree954ee36257047ac612654c5f35e18ed27deda97f /exercises/move_semantics/move_semantics1.rs
parent850a13e9133fedb2fce27884902e0aab94da9692 (diff)
right let's try this one again
Diffstat (limited to 'exercises/move_semantics/move_semantics1.rs')
-rwxr-xr-xexercises/move_semantics/move_semantics1.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs
new file mode 100755
index 0000000..37038ec
--- /dev/null
+++ b/exercises/move_semantics/move_semantics1.rs
@@ -0,0 +1,43 @@
+// move_semantics1.rs
+// Make me compile! Scroll down for hints :)
+
+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.