2014-02-05 16:33:10 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
use std::string::String;
|
2014-04-02 16:54:22 -07:00
|
|
|
|
2013-05-22 06:54:35 -04:00
|
|
|
struct StringBuffer {
|
2014-05-22 16:57:53 -07:00
|
|
|
s: String,
|
2013-05-22 06:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl StringBuffer {
|
|
|
|
pub fn append(&mut self, v: &str) {
|
2013-06-10 17:42:24 +10:00
|
|
|
self.s.push_str(v);
|
2013-05-22 06:54:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
fn to_string(sb: StringBuffer) -> String {
|
2013-05-22 06:54:35 -04:00
|
|
|
sb.s
|
|
|
|
}
|
|
|
|
|
2013-09-25 00:43:37 -07:00
|
|
|
pub fn main() {
|
2014-04-02 16:54:22 -07:00
|
|
|
let mut sb = StringBuffer {
|
2014-05-22 16:57:53 -07:00
|
|
|
s: String::new(),
|
2014-04-02 16:54:22 -07:00
|
|
|
};
|
2013-05-22 06:54:35 -04:00
|
|
|
sb.append("Hello, ");
|
|
|
|
sb.append("World!");
|
2014-06-21 03:39:03 -07:00
|
|
|
let str = to_string(sb);
|
2015-02-01 21:53:25 -05:00
|
|
|
assert_eq!(str, "Hello, World!");
|
2013-08-17 08:37:42 -07:00
|
|
|
}
|