1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use errors::Result;
use std::slice;
use translator;
use {Flavor, Loc, RpCode, RpReg, Translate, Translator};
decl_body!(pub struct RpTypeBody<F> {
pub fields: Vec<Loc<F::Field>>,
pub codes: Vec<Loc<RpCode>>,
});
pub struct Fields<'a, F: 'static>
where
F: Flavor,
{
iter: slice::Iter<'a, Loc<F::Field>>,
}
impl<'a, F: 'static> Iterator for Fields<'a, F>
where
F: Flavor,
{
type Item = &'a Loc<F::Field>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next()
}
}
impl<F> RpTypeBody<F>
where
F: Flavor,
{
pub fn fields(&self) -> Fields<F> {
Fields {
iter: self.fields.iter(),
}
}
}
impl<F: 'static, T> Translate<T> for RpTypeBody<F>
where
F: Flavor,
T: Translator<Source = F>,
{
type Source = F;
type Out = RpTypeBody<T::Target>;
fn translate(self, translator: &T) -> Result<RpTypeBody<T::Target>> {
translator.visit(&self.name)?;
let name = translator.translate_local_name(RpReg::Type, self.name)?;
Ok(RpTypeBody {
name: name,
ident: self.ident,
comment: self.comment,
decls: self.decls.translate(translator)?,
fields: translator::Fields(self.fields).translate(translator)?,
codes: self.codes,
})
}
}