rust/tests/ui/moves/move-out-of-field.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
406 B
Rust
Raw Normal View History

// run-pass
struct StringBuffer {
s: String,
}
impl StringBuffer {
pub fn append(&mut self, v: &str) {
self.s.push_str(v);
}
}
fn to_string(sb: StringBuffer) -> String {
sb.s
}
pub fn main() {
let mut sb = StringBuffer {
s: String::new(),
};
sb.append("Hello, ");
sb.append("World!");
let str = to_string(sb);
assert_eq!(str, "Hello, World!");
2013-08-17 15:37:42 +00:00
}