1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 fn to_string(&self) -> ~str;
18 fn to_string(&self) -> ~str { self.to_str() }
21 impl<T:to_str> to_str for Vec<T> {
22 fn to_string(&self) -> ~str {
23 format!("[{}]", self.iter().map(|e| e.to_string()).to_owned_vec().connect(", "))
28 assert!(1.to_string() == ~"1");
29 assert!((vec!(2, 3, 4)).to_string() == ~"[2, 3, 4]");
31 fn indirect<T:to_str>(x: T) -> ~str {
34 assert!(indirect(vec!(10, 20)) == ~"[10, 20]!");
36 fn indirect2<T:to_str>(x: T) -> ~str {
39 assert!(indirect2(vec!(1)) == ~"[1]!");