Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 1 | // Copyright 2013 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. |
| 4 | // |
| 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. |
| 10 | |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 11 | trait FooTrait { |
| 12 | fn foo(&self) -> uint; |
| 13 | } |
| 14 | |
| 15 | struct BarStruct { |
| 16 | x: uint |
| 17 | } |
| 18 | |
| 19 | impl FooTrait for BarStruct { |
| 20 | fn foo(&self) -> uint { |
| 21 | self.x |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | pub fn main() { |
| 26 | let foos: ~[ ~FooTrait ] = ~[ |
| 27 | ~BarStruct{ x: 0 } as ~FooTrait, |
| 28 | ~BarStruct{ x: 1 } as ~FooTrait, |
| 29 | ~BarStruct{ x: 2 } as ~FooTrait |
| 30 | ]; |
| 31 | |
Daniel Micay | 10089455 | 2013-08-03 16:45:23 | [diff] [blame^] | 32 | for i in range(0u, foos.len()) { |
Philipp Brüschweiler | de471a2 | 2013-06-22 07:37:40 | [diff] [blame] | 33 | assert_eq!(i, foos[i].foo()); |
| 34 | } |
| 35 | } |