1 A value was moved out while it was still borrowed.
3 Erroneous code example:
8 fn borrow(val: &Value) {}
14 let _ref_to_val: &Value = &x;
20 Here, the function `eat` takes ownership of `x`. However,
21 `x` cannot be moved because the borrow to `_ref_to_val`
22 needs to last till the function `borrow`.
23 To fix that you can do a few different things:
25 * Try to avoid moving the variable.
26 * Release borrow before move.
27 * Implement the `Copy` trait on the type.
34 fn borrow(val: &Value) {}
36 fn eat(val: &Value) {}
41 let ref_to_val: &Value = &x;
42 eat(&x); // pass by reference, if it's possible
52 fn borrow(val: &Value) {}
59 let ref_to_val: &Value = &x;
61 // ref_to_val is no longer used.
69 #[derive(Clone, Copy)] // implement Copy trait
72 fn borrow(val: &Value) {}
78 let ref_to_val: &Value = &x;
79 eat(x); // it will be copied here.
84 You can find more information about borrowing in the rust-book:
85 http://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html