2 // Test associated types appearing in struct-like enum variants.
9 fn to_index(&self) -> usize;
12 pub enum VarValue<K:UnifyKey> {
14 Root { value: K::Value, rank: usize },
17 fn get<'a,K:UnifyKey<Value=Option<V>>,V>(table: &'a Vec<VarValue<K>>, key: &K) -> &'a Option<V> {
18 match table[key.to_index()] {
19 VarValue::Redirect { to: ref k } => get(table, k),
20 VarValue::Root { value: ref v, rank: _ } => v,
24 impl UnifyKey for usize {
25 type Value = Option<char>;
26 fn to_index(&self) -> usize { *self }
30 let table = vec![/* 0 */ Redirect { to: 1 },
31 /* 1 */ Redirect { to: 3 },
32 /* 2 */ Root { value: Some('x'), rank: 0 },
33 /* 3 */ Redirect { to: 2 }];
34 assert_eq!(get(&table, &0), &Some('x'));