I'm trying to build a string by appending to it inside a for loop. For some reason the string gets moved into the for loop and I can't get it to work. I'm obviously missing something. Here's a short code snippet that exhibits this behaviour:
fn main() {
let s = format!("some string");
for x in vec!(1,2).move_iter() {
s.append("some other string");
}
}
I get the following error from the compiler (rustc 0.11.0-pre (c0a6f72 2014-06-12 14:17:13 +0000)
):
test.rs:4:9: 4:10 error: use of moved value: `s`
test.rs:4 s.append("some other string");
^
test.rs:4:9: 4:10 note: `s` moved here because it has type `collections::string::String`, which is non-copyable (perhaps you meant to use clone()?)
test.rs:4 s.append("some other string");
^
error: aborting due to previous error