rustdoc/json/
import_finder.rsuse rustc_hir::def_id::DefIdSet;
use crate::clean::{self, Import, ImportSource, Item};
use crate::fold::DocFolder;
pub(crate) fn get_imports(krate: clean::Crate) -> (clean::Crate, DefIdSet) {
let mut finder = ImportFinder::default();
let krate = finder.fold_crate(krate);
(krate, finder.imported)
}
#[derive(Default)]
struct ImportFinder {
imported: DefIdSet,
}
impl DocFolder for ImportFinder {
fn fold_item(&mut self, i: Item) -> Option<Item> {
match i.kind {
clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => {
self.imported.insert(did);
Some(i)
}
_ => Some(self.fold_item_recur(i)),
}
}
}