]>
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; | |
6 | } | |
223e47cc | 7 | |
1a4d82fc | 8 | struct Struct { |
c34b1796 | 9 | x: isize, |
1a4d82fc | 10 | } |
223e47cc | 11 | |
1a4d82fc | 12 | impl Get for Struct { |
c34b1796 AL |
13 | type Value = isize; |
14 | fn get(&self) -> &isize { | |
1a4d82fc JJ |
15 | &self.x |
16 | } | |
17 | } | |
18 | ||
19 | fn grab<T:Get>(x: &T) -> &<T as Get>::Value { | |
20 | x.get() | |
21 | } | |
223e47cc LB |
22 | |
23 | fn main() { | |
1a4d82fc JJ |
24 | let s = Struct { |
25 | x: 100, | |
223e47cc | 26 | }; |
1a4d82fc | 27 | assert_eq!(*grab(&s), 100); |
223e47cc | 28 | } |