term_rustdoc/tree/nodes/
enums.rs1use crate::tree::{
2 impls::show::{show_ids, DocTree, Show},
3 DImpl, IDMap, IDs, SliceToIds, ID,
4};
5use rustdoc_types::Enum;
6
7#[derive(serde::Serialize, serde::Deserialize, Clone)]
8pub struct DEnum {
9 pub id: ID,
10 pub variants: IDs,
11 pub impls: DImpl,
13}
14impl DEnum {
15 pub fn new(id: ID, item: &Enum, map: &IDMap) -> Self {
16 DEnum {
17 id,
18 variants: item.variants.to_ids(),
19 impls: DImpl::new(&item.impls, map),
20 }
21 }
22
23 pub fn new_external(id: ID) -> Self {
26 let (variants, impls) = Default::default();
27 DEnum {
28 id,
29 variants,
30 impls,
31 }
32 }
33
34 pub fn variants_tree(&self, map: &IDMap) -> DocTree {
35 let mut root = node!(Enum: map, &self.id);
36 names_node!(@iter self map root
37 variants Variant
38 );
39 root
40 }
41}
42
43impl Show for DEnum {
44 fn show(&self) -> DocTree {
45 "[enum]".show().with_leaves([
46 "Variants".show().with_leaves(show_ids(&self.variants)),
47 self.impls.show(),
48 ])
49 }
50
51 fn show_prettier(&self, map: &IDMap) -> DocTree {
52 let variants = names_node!(@single
53 self map NoVariants,
54 Variants variants Variant
55 );
56 node!(Enum: map, &self.id).with_leaves([variants, self.impls.show_prettier(map)])
57 }
58}