From 7413e93a4853ce5b89a86b58802775a2956959e0 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 15 Apr 2023 16:59:55 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20pretty=20print=20newlines=20in?= =?UTF-8?q?=20objects=20and=20arrays=20if=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/sql/array.rs | 8 +++++--- lib/src/sql/object.rs | 30 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/src/sql/array.rs b/lib/src/sql/array.rs index 02b272eb..3b9acbf3 100644 --- a/lib/src/sql/array.rs +++ b/lib/src/sql/array.rs @@ -153,9 +153,11 @@ impl Display for Array { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let mut f = Pretty::from(f); f.write_char('[')?; - let indent = pretty_indent(); - write!(f, "{}", Fmt::pretty_comma_separated(self.as_slice()))?; - drop(indent); + if !self.is_empty() { + let indent = pretty_indent(); + write!(f, "{}", Fmt::pretty_comma_separated(self.as_slice()))?; + drop(indent); + } f.write_char(']') } } diff --git a/lib/src/sql/object.rs b/lib/src/sql/object.rs index fdfac3cc..8f65a3c3 100644 --- a/lib/src/sql/object.rs +++ b/lib/src/sql/object.rs @@ -144,20 +144,22 @@ impl Display for Object { } else { f.write_str("{ ")?; } - let indent = pretty_indent(); - write!( - f, - "{}", - Fmt::pretty_comma_separated( - self.0.iter().map(|args| Fmt::new(args, |(k, v), f| write!( - f, - "{}: {}", - escape_key(k), - v - ))), - ) - )?; - drop(indent); + if !self.is_empty() { + let indent = pretty_indent(); + write!( + f, + "{}", + Fmt::pretty_comma_separated( + self.0.iter().map(|args| Fmt::new(args, |(k, v), f| write!( + f, + "{}: {}", + escape_key(k), + v + ))), + ) + )?; + drop(indent); + } if is_pretty() { f.write_char('}') } else {