1use std::collections::HashMap;
2
3use rustdoc_types::{Crate, Id, Item, ItemSummary};
4pub fn shake(krate: Crate) -> Crate {
6 let Crate {
7 root,
8 crate_version,
9 includes_private,
10 index,
11 paths,
12 format_version,
13 ..
14 } = krate;
15
16 let index = shake_index(index);
17 let paths = shake_paths(paths);
18 let external_crates = HashMap::default();
19
20 Crate {
21 root,
22 crate_version,
23 includes_private,
24 index,
25 paths,
26 external_crates,
27 format_version,
28 }
29}
30
31fn shake_index(index: HashMap<Id, Item>) -> HashMap<Id, Item> {
32 use rustdoc_types::ItemEnum::*;
33
34 index
35 .into_iter()
36 .filter(|(_, item)| {
37 matches!(
38 item.inner,
39 Function(_) | Method(_) | Trait(_) | Impl(_) | Typedef(_) | AssocConst { .. }
40 )
41 })
42 .collect()
43}
44
45fn shake_paths(paths: HashMap<Id, ItemSummary>) -> HashMap<Id, ItemSummary> {
46 use rustdoc_types::ItemKind::*;
47
48 paths
49 .into_iter()
50 .filter(|(_, item)| matches!(item.kind, Struct | Union | Enum | Function | Trait | Method))
51 .collect()
52}