Skip to content

Commit cdddd20

Browse files
committed
Fix metrics
1 parent c0b2b15 commit cdddd20

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

xtask/src/metrics.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub fn run_metrics() -> Result<()> {
2929
run!("git -c user.name=Bot -c [email protected] commit --message 📈")?;
3030
run!("git push origin master")?;
3131
}
32-
eprintln!("{:#?}\n", metrics);
33-
eprintln!("{}", metrics.json());
32+
eprintln!("{:#?}", metrics);
3433
Ok(())
3534
}
3635

@@ -152,26 +151,32 @@ impl Host {
152151
}
153152
}
154153

154+
struct State {
155+
obj: bool,
156+
first: bool,
157+
}
158+
155159
#[derive(Default)]
156160
struct Json {
157-
object_comma: bool,
158-
array_comma: bool,
161+
stack: Vec<State>,
159162
buf: String,
160163
}
161164

162165
impl Json {
163166
fn begin_object(&mut self) {
164-
self.object_comma = false;
167+
self.stack.push(State { obj: true, first: true });
165168
self.buf.push('{');
166169
}
167170
fn end_object(&mut self) {
171+
self.stack.pop();
168172
self.buf.push('}')
169173
}
170174
fn begin_array(&mut self) {
171-
self.array_comma = false;
175+
self.stack.push(State { obj: false, first: true });
172176
self.buf.push('[');
173177
}
174178
fn end_array(&mut self) {
179+
self.stack.pop();
175180
self.buf.push(']')
176181
}
177182
fn field(&mut self, name: &str) {
@@ -194,17 +199,22 @@ impl Json {
194199
}
195200

196201
fn array_comma(&mut self) {
197-
if self.array_comma {
202+
let state = self.stack.last_mut().unwrap();
203+
if state.obj {
204+
return;
205+
}
206+
if !state.first {
198207
self.buf.push(',');
199208
}
200-
self.array_comma = true;
209+
state.first = false;
201210
}
202211

203212
fn object_comma(&mut self) {
204-
if self.object_comma {
213+
let state = self.stack.last_mut().unwrap();
214+
if !state.first {
205215
self.buf.push(',');
206216
}
207-
self.object_comma = true;
217+
state.first = false;
208218
}
209219
}
210220

0 commit comments

Comments
 (0)