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
use super::{Fmt, Formatter};
use wast::{Id, Index};

impl<'src> Fmt for &Vec<Index<'src>> {
    fn fmt(&self, formatter: &mut Formatter) {
        let mut iter = self.iter();
        if let Some(index) = iter.next() {
            formatter.fmt(index);
        }
        for index in iter {
            formatter.write(" ");
            formatter.fmt(index);
        }
    }
}

impl<'src> Fmt for &Index<'src> {
    fn fmt(&self, formatter: &mut Formatter) {
        match self {
            Index::Num(n, ..) => formatter.fmt(*n),
            Index::Id(id) => formatter.fmt(id),
        };
    }
}

impl<'src> Fmt for &Id<'src> {
    fn fmt(&self, formatter: &mut Formatter) {
        formatter.write("$");
        formatter.write(self.name());
    }
}