term_rustdoc/tree/stats/
impls.rs1use super::{ImplCount, ImplCounts, ImplKind, ItemCount};
2use std::ops::{Add, AddAssign};
3
4pub fn acc_sum<T: Add + AddAssign>(mut acc: T, new: T) -> T {
5 acc += new;
6 acc
7}
8
9impl Add for ItemCount {
10 type Output = ItemCount;
11
12 fn add(self, rhs: Self) -> Self::Output {
13 ItemCount {
14 modules: self.modules + rhs.modules,
15 structs: self.structs + rhs.structs,
16 unions: self.unions + rhs.unions,
17 enums: self.enums + rhs.enums,
18 functions: self.functions + rhs.functions,
19 traits: self.traits + rhs.traits,
20 constants: self.constants + rhs.constants,
21 statics: self.statics + rhs.statics,
22 type_alias: self.type_alias + rhs.type_alias,
23 macros_decl: self.macros_decl + rhs.macros_decl,
24 macros_func: self.macros_func + rhs.macros_func,
25 macros_attr: self.macros_attr + rhs.macros_attr,
26 macros_derv: self.macros_derv + rhs.macros_derv,
27 }
28 }
29}
30
31impl Add for ImplKind {
32 type Output = ImplKind;
33
34 fn add(self, rhs: Self) -> Self::Output {
35 match (self, rhs) {
36 (ImplKind::Inherent, ImplKind::Inherent) => ImplKind::Inherent,
37 (ImplKind::Trait, ImplKind::Trait) => ImplKind::Trait,
38 _ => ImplKind::Both,
39 }
40 }
41}
42
43impl AddAssign for ImplKind {
44 fn add_assign(&mut self, rhs: Self) {
45 *self = match (&self, rhs) {
46 (ImplKind::Inherent, ImplKind::Inherent) => ImplKind::Inherent,
47 (ImplKind::Trait, ImplKind::Trait) => ImplKind::Trait,
48 _ => ImplKind::Both,
49 };
50 }
51}
52
53impl AddAssign for ImplCount {
54 fn add_assign(&mut self, rhs: Self) {
55 self.structs += rhs.structs;
56 self.enums += rhs.enums;
57 self.unions += rhs.unions;
58 self.kind += rhs.kind;
59 self.total += rhs.total;
60 }
61}
62
63impl Add for ImplCount {
64 type Output = ImplCount;
65
66 fn add(self, rhs: Self) -> Self::Output {
67 ImplCount {
68 structs: self.structs + rhs.structs,
69 enums: self.enums + rhs.enums,
70 unions: self.unions + rhs.unions,
71 kind: self.kind + rhs.kind,
72 total: self.total + rhs.total,
73 }
74 }
75}
76
77impl AddAssign for ItemCount {
78 fn add_assign(&mut self, rhs: Self) {
79 self.modules += rhs.modules;
80 self.structs += rhs.structs;
81 self.unions += rhs.unions;
82 self.enums += rhs.enums;
83 self.functions += rhs.functions;
84 self.traits += rhs.traits;
85 self.constants += rhs.constants;
86 self.statics += rhs.statics;
87 self.type_alias += rhs.type_alias;
88 self.macros_decl += rhs.macros_decl;
89 self.macros_func += rhs.macros_func;
90 self.macros_attr += rhs.macros_attr;
91 self.macros_derv += rhs.macros_derv;
92 }
93}
94
95impl Add for ImplCounts {
96 type Output = ImplCounts;
97
98 fn add(self, rhs: Self) -> Self::Output {
99 ImplCounts {
100 inherent: self.inherent + rhs.trait_,
101 trait_: self.trait_ + rhs.trait_,
102 total: self.total + rhs.total,
103 }
104 }
105}
106
107impl AddAssign for ImplCounts {
108 fn add_assign(&mut self, rhs: Self) {
109 self.inherent += rhs.trait_;
110 self.trait_ += rhs.trait_;
111 self.total += rhs.total;
112 }
113}