1 // Copyright 2012 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.
11 // Tests that type assignability is used to search for instances when
12 // making method calls, but only if there aren't any matches without
16 fn iterate(&self, blk: |x: &A| -> bool) -> bool;
19 impl<'a,A> iterable<A> for &'a [A] {
20 fn iterate(&self, f: |x: &A| -> bool) -> bool {
21 self.iter().advance(f)
25 impl<A> iterable<A> for Vec<A> {
26 fn iterate(&self, f: |x: &A| -> bool) -> bool {
27 self.iter().advance(f)
31 fn length<A, T: iterable<A>>(x: T) -> uint {
41 let x = vec!(0,1,2,3);
43 x.iterate(|y| { assert!(x[*y] == *y); true });
44 // Call a parameterized function
45 assert_eq!(length(x.clone()), x.len());
46 // Call a parameterized function, with type arguments that require
48 assert_eq!(length::<int, &[int]>(x), x.len());
50 // Now try it with a type that *needs* to be borrowed
53 z.iterate(|y| { assert!(z[*y] == *y); true });
54 // Call a parameterized function
55 assert_eq!(length::<int, &[int]>(z), z.len());