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.
13 // pretty-expanded FIXME #23616
16 fn to_string_(&self) -> String;
19 fn to_string_(&self) -> String { self.to_string() }
21 impl to_str for String {
22 fn to_string_(&self) -> String { self.clone() }
25 fn to_string_(&self) -> String { "()".to_string() }
29 fn map<U, F>(&self, f: F) -> Vec<U> where F: FnMut(&T) -> U;
31 impl<T> map<T> for Vec<T> {
32 fn map<U, F>(&self, mut f: F) -> Vec<U> where F: FnMut(&T) -> U {
33 let mut r = Vec::new();
41 fn foo<U, T: map<U>>(x: T) -> Vec<String> {
42 x.map(|_e| "hi".to_string() )
44 fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> {
45 x.map(|_e| _e.to_string_() )
49 assert_eq!(foo(vec!(1)), ["hi".to_string()]);
50 assert_eq!(bar::<int, Vec<int> >(vec!(4, 5)), ["4".to_string(), "5".to_string()]);
51 assert_eq!(bar::<String, Vec<String> >(vec!("x".to_string(), "y".to_string())),
52 ["x".to_string(), "y".to_string()]);
53 assert_eq!(bar::<(), Vec<()>>(vec!(())), ["()".to_string()]);