]>
Commit | Line | Data |
---|---|---|
7cac9316 XL |
1 | // Copyright 2015 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 | ||
11 | #![feature(specialization)] | |
12 | ||
13 | pub trait Foo { | |
14 | fn foo(&self) -> &'static str; | |
15 | } | |
16 | ||
17 | default impl<T> Foo for T { | |
18 | fn foo(&self) -> &'static str { | |
19 | "generic" | |
20 | } | |
21 | } | |
22 | ||
23 | default impl<T: Clone> Foo for T { | |
24 | fn foo(&self) -> &'static str { | |
25 | "generic Clone" | |
26 | } | |
27 | } | |
28 | ||
29 | default impl<T, U> Foo for (T, U) where T: Clone, U: Clone { | |
30 | fn foo(&self) -> &'static str { | |
31 | "generic pair" | |
32 | } | |
33 | } | |
34 | ||
35 | default impl<T: Clone> Foo for (T, T) { | |
36 | fn foo(&self) -> &'static str { | |
37 | "generic uniform pair" | |
38 | } | |
39 | } | |
40 | ||
41 | default impl Foo for (u8, u32) { | |
42 | fn foo(&self) -> &'static str { | |
43 | "(u8, u32)" | |
44 | } | |
45 | } | |
46 | ||
47 | default impl Foo for (u8, u8) { | |
48 | fn foo(&self) -> &'static str { | |
49 | "(u8, u8)" | |
50 | } | |
51 | } | |
52 | ||
53 | default impl<T: Clone> Foo for Vec<T> { | |
54 | fn foo(&self) -> &'static str { | |
55 | "generic Vec" | |
56 | } | |
57 | } | |
58 | ||
59 | impl Foo for Vec<i32> { | |
60 | fn foo(&self) -> &'static str { | |
61 | "Vec<i32>" | |
62 | } | |
63 | } | |
64 | ||
65 | impl Foo for String { | |
66 | fn foo(&self) -> &'static str { | |
67 | "String" | |
68 | } | |
69 | } | |
70 | ||
71 | impl Foo for i32 { | |
72 | fn foo(&self) -> &'static str { | |
73 | "i32" | |
74 | } | |
75 | } | |
76 | ||
77 | pub trait MyMarker {} | |
78 | default impl<T: Clone + MyMarker> Foo for T { | |
79 | fn foo(&self) -> &'static str { | |
80 | "generic Clone + MyMarker" | |
81 | } | |
82 | } |