term_rustdoc/tree/
mod.rs

1#[macro_use]
2mod impls;
3// The inner macro `icon!` can be used afterwards in submods
4
5mod id;
6mod nodes;
7mod stats;
8mod tag;
9mod textline;
10
11use rustdoc_types::Crate;
12use std::{fmt, ops::Deref, rc::Rc};
13
14pub use id::{IDMap, IDs, IdAsStr, IdToID, IndexMap, PathMap, SliceToIds, ID};
15pub use impls::show::{DocTree, Show};
16pub use nodes::{
17    DConstant, DEnum, DFunction, DImpl, DImplInner, DMacroAttr, DMacroDecl, DMacroDerv, DMacroFunc,
18    DModule, DStatic, DStruct, DTrait, DTypeAlias, DUnion, DataItemKind,
19};
20pub use stats::{ImplCount, ImplCounts, ImplKind, ItemCount};
21pub use tag::Tag;
22pub use textline::{Text, TextTag, TreeLine, TreeLines};
23
24/// This should be the main data structure to refer to documentation
25/// and the items tree structure in public modules.
26///
27/// It's cheap to clone and use a ID buffer to avoid the cost of generating a new string in query.
28#[derive(Clone, Default, serde::Serialize, serde::Deserialize)]
29pub struct CrateDoc {
30    inner: Rc<IDMap>,
31}
32
33impl CrateDoc {
34    pub fn new(doc: Crate) -> CrateDoc {
35        CrateDoc {
36            inner: Rc::new(IDMap::new(doc)),
37        }
38    }
39}
40
41impl Deref for CrateDoc {
42    type Target = IDMap;
43
44    fn deref(&self) -> &Self::Target {
45        &self.inner
46    }
47}
48
49impl fmt::Debug for CrateDoc {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        write!(f, "CrateDoc for {}", self.name(&self.dmodule().id))
52    }
53}