summaryrefslogtreecommitdiff
path: root/src/compute/table.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-17 23:45:03 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-17 23:45:03 +0200
commit6d7e7d945b315469b80bca3466a96534b2a17639 (patch)
tree1b6c5e0ae7fb683ff7f3b6b1d961151a8e467a80 /src/compute/table.rs
parent3cbca56a7195bb2a7996530d584300d697c11dc8 (diff)
Tidy up library functions 🧺
Diffstat (limited to 'src/compute/table.rs')
-rw-r--r--src/compute/table.rs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/compute/table.rs b/src/compute/table.rs
index 75effd60..e8c4b307 100644
--- a/src/compute/table.rs
+++ b/src/compute/table.rs
@@ -1,7 +1,7 @@
//! A key-value map that can also model array-like structures.
use std::collections::BTreeMap;
-use std::fmt::{self, Debug, Formatter};
+use std::fmt::{self, Debug, Display, Formatter};
use std::ops::Index;
use crate::syntax::span::{Span, Spanned};
@@ -180,25 +180,31 @@ impl<V: Debug> Debug for Table<V> {
let mut builder = f.debug_tuple("");
- struct Entry<'a>(&'a dyn Debug, &'a dyn Debug);
+ struct Entry<'a>(bool, &'a dyn Display, &'a dyn Debug);
impl<'a> Debug for Entry<'a> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- self.0.fmt(f)?;
+ if self.0 {
+ f.write_str("\"")?;
+ }
+ self.1.fmt(f)?;
+ if self.0 {
+ f.write_str("\"")?;
+ }
if f.alternate() {
f.write_str(" = ")?;
} else {
f.write_str("=")?;
}
- self.1.fmt(f)
+ self.2.fmt(f)
}
}
for (key, value) in self.nums() {
- builder.field(&Entry(&key, &value));
+ builder.field(&Entry(false, &key, &value));
}
for (key, value) in self.strs() {
- builder.field(&Entry(&key, &value));
+ builder.field(&Entry(key.contains(' '), &key, &value));
}
builder.finish()
@@ -358,21 +364,21 @@ mod tests {
#[test]
fn test_table_format_debug() {
let mut table = Table::new();
- assert_eq!(format!("{:?}", table), r#"()"#);
- assert_eq!(format!("{:#?}", table), r#"()"#);
+ assert_eq!(format!("{:?}", table), "()");
+ assert_eq!(format!("{:#?}", table), "()");
table.insert(10, "hello");
table.insert("twenty", "there");
table.insert("sp ace", "quotes");
assert_eq!(
format!("{:?}", table),
- r#"(10="hello", "sp ace"="quotes", "twenty"="there")"#,
+ r#"(10="hello", "sp ace"="quotes", twenty="there")"#,
);
assert_eq!(format!("{:#?}", table).lines().collect::<Vec<_>>(), [
"(",
r#" 10 = "hello","#,
r#" "sp ace" = "quotes","#,
- r#" "twenty" = "there","#,
+ r#" twenty = "there","#,
")",
]);
}