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) -> String;
17 fn to_string_(&self) -> String { self.to_string() }
19 impl to_str for String {
20 fn to_string_(&self) -> String { self.clone() }
23 fn to_string_(&self) -> String { "()".to_string() }
27 fn map<U>(&self, f: |&T| -> U) -> Vec<U> ;
29 impl<T> map<T> for Vec<T> {
30 fn map<U>(&self, f: |&T| -> U) -> Vec<U> {
31 let mut r = Vec::new();
32 for i in self.iter() {
39 fn foo<U, T: map<U>>(x: T) -> Vec<String> {
40 x.map(|_e| "hi".to_string() )
42 fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> {
43 x.map(|_e| _e.to_string_() )
47 assert_eq!(foo(vec!(1i)), vec!("hi".to_string()));
48 assert_eq!(bar::<int, Vec<int> >(vec!(4, 5)), vec!("4".to_string(), "5".to_string()));
49 assert_eq!(bar::<String, Vec<String> >(vec!("x".to_string(), "y".to_string())),
50 vec!("x".to_string(), "y".to_string()));
51 assert_eq!(bar::<(), Vec<()>>(vec!(())), vec!("()".to_string()));