summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-03-31 15:38:30 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-01 17:01:26 +0200
commit6e17b500e26288a245434c3e05de37f7dff08605 (patch)
treedc9ab111ff3efd0d7e28abd61f4f206e6f448099
parent0e651879939ca18b7ce38ffb306c85a183deb67b (diff)
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 <mail@beyermatthias.de>
-rw-r--r--src/value.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/value.rs b/src/value.rs
index 2c0873c..39d66bf 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -94,10 +94,15 @@ impl Display for ValueKind {
ValueKind::Integer(value) => write!(f, "{}", value),
ValueKind::Float(value) => write!(f, "{}", value),
ValueKind::Nil => write!(f, "nil"),
-
- // TODO: Figure out a nice Display for these
- ValueKind::Table(ref table) => write!(f, "{:?}", table),
- ValueKind::Array(ref array) => write!(f, "{:?}", array),
+ ValueKind::Table(ref table) => write!(f, "{{ {} }}", {
+ table
+ .iter()
+ .map(|(k, v)| format!("{} => {}, ", k, v))
+ .collect::<String>()
+ }),
+ ValueKind::Array(ref array) => write!(f, "{:?}", {
+ array.iter().map(|e| format!("{}, ", e)).collect::<String>()
+ }),
}
}
}