1 // Copyright 2012-4 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
<F
>(&self, blk
: F
) -> bool
where F
: FnMut(&A
) -> bool
;
19 impl<'a
,A
> iterable
<A
> for &'a
[A
] {
20 fn iterate
<F
>(&self, f
: F
) -> bool
where F
: FnMut(&A
) -> bool
{
25 impl<A
> iterable
<A
> for Vec
<A
> {
26 fn iterate
<F
>(&self, f
: F
) -> bool
where F
: FnMut(&A
) -> bool
{
31 fn length
<A
, T
: iterable
<A
>>(x
: T
) -> usize {
41 let x
: Vec
<isize> = vec
![0,1,2,3];
43 x
.iterate(|y
| { assert_eq!(x[*y as usize], *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
::<isize, &[isize]>(&*x
), x
.len());
50 // Now try it with a type that *needs* to be borrowed
52 // Call a parameterized function
53 assert_eq
!(length
::<isize, &[isize]>(&z
), z
.len());