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