2 #![allow(non_camel_case_types)]
4 // Tests that type assignability is used to search for instances when
5 // making method calls, but only if there aren't any matches without
9 fn iterate<F>(&self, blk: F) -> bool where F: FnMut(&A) -> bool;
12 impl<'a,A> iterable<A> for &'a [A] {
13 fn iterate<F>(&self, f: F) -> bool where F: FnMut(&A) -> bool {
18 impl<A> iterable<A> for Vec<A> {
19 fn iterate<F>(&self, f: F) -> bool where F: FnMut(&A) -> bool {
24 fn length<A, T: iterable<A>>(x: T) -> usize {
34 let x: Vec<isize> = vec![0,1,2,3];
36 x.iterate(|y| { assert_eq!(x[*y as usize], *y); true });
37 // Call a parameterized function
38 assert_eq!(length(x.clone()), x.len());
39 // Call a parameterized function, with type arguments that require
41 assert_eq!(length::<isize, &[isize]>(&*x), x.len());
43 // Now try it with a type that *needs* to be borrowed
45 // Call a parameterized function
46 assert_eq!(length::<isize, &[isize]>(&z), z.len());