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.
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.
11 // Test associated types appearing in struct-like enum variants.
13 use self::VarValue
::*;
17 fn to_index(&self) -> usize;
20 pub enum VarValue
<K
:UnifyKey
> {
22 Root { value: K::Value, rank: usize }
,
25 fn get
<'a
,K
:UnifyKey
<Value
=Option
<V
>>,V
>(table
: &'a Vec
<VarValue
<K
>>, key
: &K
) -> &'a Option
<V
> {
26 match table
[key
.to_index()] {
27 VarValue
::Redirect { to: ref k }
=> get(table
, k
),
28 VarValue
::Root { value: ref v, rank: _ }
=> v
,
32 impl UnifyKey
for usize {
33 type Value
= Option
<char>;
34 fn to_index(&self) -> usize { *self }
38 let table
= vec
![/* 0 */ Redirect { to: 1 }
,
39 /* 1 */ Redirect { to: 3 }
,
40 /* 2 */ Root { value: Some('x'), rank: 0 }
,
41 /* 3 */ Redirect { to: 2 }
];
42 assert_eq
!(get(&table
, &0), &Some('x'
));