2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2013-05-22 10:54:35 +00:00
|
|
|
struct StringBuffer {
|
2014-05-22 23:57:53 +00:00
|
|
|
s: String,
|
2013-05-22 10:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl StringBuffer {
|
|
|
|
pub fn append(&mut self, v: &str) {
|
2013-06-10 07:42:24 +00:00
|
|
|
self.s.push_str(v);
|
2013-05-22 10:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-21 10:39:03 +00:00
|
|
|
fn to_string(sb: StringBuffer) -> String {
|
2013-05-22 10:54:35 +00:00
|
|
|
sb.s
|
|
|
|
}
|
|
|
|
|
2013-09-25 07:43:37 +00:00
|
|
|
pub fn main() {
|
2014-04-02 23:54:22 +00:00
|
|
|
let mut sb = StringBuffer {
|
2014-05-22 23:57:53 +00:00
|
|
|
s: String::new(),
|
2014-04-02 23:54:22 +00:00
|
|
|
};
|
2013-05-22 10:54:35 +00:00
|
|
|
sb.append("Hello, ");
|
|
|
|
sb.append("World!");
|
2014-06-21 10:39:03 +00:00
|
|
|
let str = to_string(sb);
|
2015-02-02 02:53:25 +00:00
|
|
|
assert_eq!(str, "Hello, World!");
|
2013-08-17 15:37:42 +00:00
|
|
|
}
|