1#![allow(missing_docs)]
2
3use crate::{
89 Array, ArrayOfTables, Datetime, Document, Formatted, InlineTable, Item, KeyMut, Table,
90 TableLike, Value,
91};
92
93pub trait VisitMut {
97 fn visit_document_mut(&mut self, node: &mut Document) {
98 visit_document_mut(self, node);
99 }
100
101 fn visit_item_mut(&mut self, node: &mut Item) {
102 visit_item_mut(self, node);
103 }
104
105 fn visit_table_mut(&mut self, node: &mut Table) {
106 visit_table_mut(self, node);
107 }
108
109 fn visit_inline_table_mut(&mut self, node: &mut InlineTable) {
110 visit_inline_table_mut(self, node)
111 }
112
113 fn visit_table_like_mut(&mut self, node: &mut dyn TableLike) {
116 visit_table_like_mut(self, node);
117 }
118
119 fn visit_table_like_kv_mut(&mut self, key: KeyMut<'_>, node: &mut Item) {
120 visit_table_like_kv_mut(self, key, node);
121 }
122
123 fn visit_array_mut(&mut self, node: &mut Array) {
124 visit_array_mut(self, node);
125 }
126
127 fn visit_array_of_tables_mut(&mut self, node: &mut ArrayOfTables) {
128 visit_array_of_tables_mut(self, node);
129 }
130
131 fn visit_value_mut(&mut self, node: &mut Value) {
132 visit_value_mut(self, node);
133 }
134
135 fn visit_boolean_mut(&mut self, node: &mut Formatted<bool>) {
136 visit_boolean_mut(self, node)
137 }
138
139 fn visit_datetime_mut(&mut self, node: &mut Formatted<Datetime>) {
140 visit_datetime_mut(self, node);
141 }
142
143 fn visit_float_mut(&mut self, node: &mut Formatted<f64>) {
144 visit_float_mut(self, node)
145 }
146
147 fn visit_integer_mut(&mut self, node: &mut Formatted<i64>) {
148 visit_integer_mut(self, node)
149 }
150
151 fn visit_string_mut(&mut self, node: &mut Formatted<String>) {
152 visit_string_mut(self, node)
153 }
154}
155
156pub fn visit_document_mut<V>(v: &mut V, node: &mut Document)
157where
158 V: VisitMut + ?Sized,
159{
160 v.visit_table_mut(node.as_table_mut());
161}
162
163pub fn visit_item_mut<V>(v: &mut V, node: &mut Item)
164where
165 V: VisitMut + ?Sized,
166{
167 match node {
168 Item::None => {}
169 Item::Value(value) => v.visit_value_mut(value),
170 Item::Table(table) => v.visit_table_mut(table),
171 Item::ArrayOfTables(array) => v.visit_array_of_tables_mut(array),
172 }
173}
174
175pub fn visit_table_mut<V>(v: &mut V, node: &mut Table)
176where
177 V: VisitMut + ?Sized,
178{
179 v.visit_table_like_mut(node);
180}
181
182pub fn visit_inline_table_mut<V>(v: &mut V, node: &mut InlineTable)
183where
184 V: VisitMut + ?Sized,
185{
186 v.visit_table_like_mut(node);
187}
188
189pub fn visit_table_like_mut<V>(v: &mut V, node: &mut dyn TableLike)
190where
191 V: VisitMut + ?Sized,
192{
193 for (key, item) in node.iter_mut() {
194 v.visit_table_like_kv_mut(key, item);
195 }
196}
197
198pub fn visit_table_like_kv_mut<V>(v: &mut V, _key: KeyMut<'_>, node: &mut Item)
199where
200 V: VisitMut + ?Sized,
201{
202 v.visit_item_mut(node)
203}
204
205pub fn visit_array_mut<V>(v: &mut V, node: &mut Array)
206where
207 V: VisitMut + ?Sized,
208{
209 for value in node.iter_mut() {
210 v.visit_value_mut(value);
211 }
212}
213
214pub fn visit_array_of_tables_mut<V>(v: &mut V, node: &mut ArrayOfTables)
215where
216 V: VisitMut + ?Sized,
217{
218 for table in node.iter_mut() {
219 v.visit_table_mut(table);
220 }
221}
222
223pub fn visit_value_mut<V>(v: &mut V, node: &mut Value)
224where
225 V: VisitMut + ?Sized,
226{
227 match node {
228 Value::String(s) => v.visit_string_mut(s),
229 Value::Integer(i) => v.visit_integer_mut(i),
230 Value::Float(f) => v.visit_float_mut(f),
231 Value::Boolean(b) => v.visit_boolean_mut(b),
232 Value::Datetime(dt) => v.visit_datetime_mut(dt),
233 Value::Array(array) => v.visit_array_mut(array),
234 Value::InlineTable(table) => v.visit_inline_table_mut(table),
235 }
236}
237
238macro_rules! empty_visit_mut {
239 ($name: ident, $t: ty) => {
240 fn $name<V>(_v: &mut V, _node: &mut $t)
241 where
242 V: VisitMut + ?Sized,
243 {
244 }
245 };
246}
247
248empty_visit_mut!(visit_boolean_mut, Formatted<bool>);
249empty_visit_mut!(visit_datetime_mut, Formatted<Datetime>);
250empty_visit_mut!(visit_float_mut, Formatted<f64>);
251empty_visit_mut!(visit_integer_mut, Formatted<i64>);
252empty_visit_mut!(visit_string_mut, Formatted<String>);