]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
c34b1796 | 2 | |
1a4d82fc JJ |
3 | trait Get { |
4 | type Value; | |
5 | fn get(&self) -> &<Self as Get>::Value; | |
223e47cc LB |
6 | } |
7 | ||
1a4d82fc | 8 | struct Struct { |
c34b1796 | 9 | x: isize, |
223e47cc LB |
10 | } |
11 | ||
1a4d82fc | 12 | impl Get for Struct { |
c34b1796 AL |
13 | type Value = isize; |
14 | fn get(&self) -> &isize { | |
1a4d82fc | 15 | &self.x |
223e47cc LB |
16 | } |
17 | } | |
18 | ||
1a4d82fc JJ |
19 | impl Struct { |
20 | fn grab<T:Get>(x: &T) -> &<T as Get>::Value { | |
21 | x.get() | |
22 | } | |
23 | } | |
223e47cc LB |
24 | |
25 | fn main() { | |
1a4d82fc JJ |
26 | let s = Struct { |
27 | x: 100, | |
28 | }; | |
29 | assert_eq!(*Struct::grab(&s), 100); | |
223e47cc | 30 | } |