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
use std::cmp::Ordering;
use std::collections::HashSet;
use bindgen::ir::{ItemContainer, Path};
pub struct Dependencies {
pub order: Vec<ItemContainer>,
pub items: HashSet<Path>,
}
impl Dependencies {
pub fn new() -> Dependencies {
Dependencies {
order: Vec::new(),
items: HashSet::new(),
}
}
pub fn sort(&mut self) {
let ordering = |a: &ItemContainer, b: &ItemContainer| match (a, b) {
(&ItemContainer::Enum(ref x), &ItemContainer::Enum(ref y))
if x.tag.is_none() && y.tag.is_none() =>
{
x.path.cmp(&y.path)
}
(&ItemContainer::Enum(ref x), _) if x.tag.is_none() => Ordering::Less,
(_, &ItemContainer::Enum(ref x)) if x.tag.is_none() => Ordering::Greater,
(&ItemContainer::OpaqueItem(ref x), &ItemContainer::OpaqueItem(ref y)) => {
x.path.cmp(&y.path)
}
(&ItemContainer::OpaqueItem(_), _) => Ordering::Less,
(_, &ItemContainer::OpaqueItem(_)) => Ordering::Greater,
_ => Ordering::Equal,
};
self.order.sort_by(ordering);
}
}