wot_td/builder/
human_readable_info.rs1use alloc::{string::*, vec::Vec};
7
8use super::MultiLanguageBuilder;
9
10#[derive(Debug, Default, Clone, PartialEq, Eq)]
12pub struct HumanReadableInfo {
13 pub(super) attype: Option<Vec<String>>,
16 pub(super) title: Option<String>,
18 pub(super) titles: Option<MultiLanguageBuilder<String>>,
20 pub(super) description: Option<String>,
22 pub(super) descriptions: Option<MultiLanguageBuilder<String>>,
24}
25
26pub trait BuildableHumanReadableInfo {
28 fn attype(self, value: impl Into<String>) -> Self;
32
33 fn title(self, value: impl Into<String>) -> Self;
37
38 fn titles<F>(self, f: F) -> Self
46 where
47 F: FnOnce(&mut MultiLanguageBuilder<String>) -> &mut MultiLanguageBuilder<String>;
48
49 fn description(self, value: impl Into<String>) -> Self;
53
54 fn descriptions<F>(self, f: F) -> Self
62 where
63 F: FnOnce(&mut MultiLanguageBuilder<String>) -> &mut MultiLanguageBuilder<String>;
64}
65
66impl BuildableHumanReadableInfo for HumanReadableInfo {
67 fn attype(mut self, value: impl Into<String>) -> Self {
68 self.attype
69 .get_or_insert_with(Default::default)
70 .push(value.into());
71 self
72 }
73
74 fn title(mut self, value: impl Into<String>) -> Self {
75 self.title = Some(value.into());
76 self
77 }
78
79 fn titles<F>(mut self, f: F) -> Self
80 where
81 F: FnOnce(&mut MultiLanguageBuilder<String>) -> &mut MultiLanguageBuilder<String>,
82 {
83 let mut builder = MultiLanguageBuilder::default();
84 f(&mut builder);
85 self.titles = Some(builder);
86 self
87 }
88
89 fn description(mut self, value: impl Into<String>) -> Self {
90 self.description = Some(value.into());
91 self
92 }
93
94 fn descriptions<F>(mut self, f: F) -> Self
95 where
96 F: FnOnce(&mut MultiLanguageBuilder<String>) -> &mut MultiLanguageBuilder<String>,
97 {
98 let mut builder = MultiLanguageBuilder::default();
99 f(&mut builder);
100 self.descriptions = Some(builder);
101 self
102 }
103}
104
105macro_rules! impl_delegate_buildable_hr_info {
106 ($( $ty:ident $( < $( $generic:ident $(: $bound:ident)? ),+ > )? on $($inner_path:ident).+ ),+ $(,)?) => {
107 $(
108 impl $(< $($generic $(: $bound)? ),+ >)? BuildableHumanReadableInfo for $ty $(< $($generic),+ >)?
109 {
110 #[inline]
111 fn attype(mut self, value: impl Into<String>) -> Self {
112 self. $($inner_path).+ = self. $($inner_path).+ .attype(value);
113 self
114 }
115
116 #[inline]
117 fn title(mut self, value: impl Into<String>) -> Self {
118 self. $($inner_path).+ = self. $($inner_path).+ .title(value);
119 self
120 }
121
122 #[inline]
123 fn titles<F>(mut self, f: F) -> Self
124 where
125 F: FnOnce(&mut MultiLanguageBuilder<String>) -> &mut MultiLanguageBuilder<String>,
126 {
127 self. $($inner_path).+ = self. $($inner_path).+ .titles(f);
128 self
129 }
130
131 #[inline]
132 fn description(mut self, value: impl Into<String>) -> Self {
133 self. $($inner_path).+ = self. $($inner_path).+ .description(value);
134 self
135 }
136
137 #[inline]
138 fn descriptions<F>(mut self, f: F) -> Self
139 where
140 F: FnOnce(&mut MultiLanguageBuilder<String>) -> &mut MultiLanguageBuilder<String>,
141 {
142 self. $($inner_path).+ = self. $($inner_path).+ .descriptions(f);
143 self
144 }
145 }
146 )+
147 };
148}
149
150pub(super) use impl_delegate_buildable_hr_info;