blob: c9d0fde6d3c2f83d698c75c5750908981cfa339d [file] [log] [blame]
Philipp Brüschweilerde471a22013-06-22 07:37:401// 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üschweilerde471a22013-06-22 07:37:4011trait FooTrait {
12 fn foo(&self) -> uint;
13}
14
15struct BarStruct {
16 x: uint
17}
18
19impl FooTrait for BarStruct {
20 fn foo(&self) -> uint {
21 self.x
22 }
23}
24
25pub 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 Micay100894552013-08-03 16:45:2332 for i in range(0u, foos.len()) {
Philipp Brüschweilerde471a22013-06-22 07:37:4033 assert_eq!(i, foos[i].foo());
34 }
35}