mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-05 13:13:40 +00:00
28 lines
432 B
Rust
28 lines
432 B
Rust
// run-pass
|
|
|
|
use std::string::String;
|
|
|
|
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!");
|
|
}
|