Skip to content

Commit 6e17b50

Browse files
committed
Provide a nice Display impl for ValueKind::{Array, Table}
This patch changes the Display impl for ValueKind so that Array and Table are nicely displayed. This basically changes a user-facing implementation in a non-backwards-compatible way. But as the documentation for std states: Display is similar to Debug, but Display is for user-facing output [...] This is user-facing and I'd say this is okay. Signed-off-by: Matthias Beyer <[email protected]>
1 parent 0e65187 commit 6e17b50

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/value.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,15 @@ impl Display for ValueKind {
9494
ValueKind::Integer(value) => write!(f, "{}", value),
9595
ValueKind::Float(value) => write!(f, "{}", value),
9696
ValueKind::Nil => write!(f, "nil"),
97-
98-
// TODO: Figure out a nice Display for these
99-
ValueKind::Table(ref table) => write!(f, "{:?}", table),
100-
ValueKind::Array(ref array) => write!(f, "{:?}", array),
97+
ValueKind::Table(ref table) => write!(f, "{{ {} }}", {
98+
table
99+
.iter()
100+
.map(|(k, v)| format!("{} => {}, ", k, v))
101+
.collect::<String>()
102+
}),
103+
ValueKind::Array(ref array) => write!(f, "{:?}", {
104+
array.iter().map(|e| format!("{}, ", e)).collect::<String>()
105+
}),
101106
}
102107
}
103108
}

0 commit comments

Comments
 (0)