Skip to content

Commit 4a530b8

Browse files
committed
Fix clippy: Rewrite string building
Clippy complained about how we build the strings here, so rewrite it. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1 parent 39457c8 commit 4a530b8

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/value.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ where
152152

153153
impl Display for ValueKind {
154154
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
155+
use std::fmt::Write;
156+
155157
match *self {
156158
Self::String(ref value) => write!(f, "{}", value),
157159
Self::Boolean(value) => write!(f, "{}", value),
@@ -161,15 +163,20 @@ impl Display for ValueKind {
161163
Self::U128(value) => write!(f, "{}", value),
162164
Self::Float(value) => write!(f, "{}", value),
163165
Self::Nil => write!(f, "nil"),
164-
Self::Table(ref table) => write!(f, "{{ {} }}", {
165-
table
166-
.iter()
167-
.map(|(k, v)| format!("{} => {}, ", k, v))
168-
.collect::<String>()
169-
}),
170-
Self::Array(ref array) => write!(f, "{:?}", {
171-
array.iter().map(|e| format!("{}, ", e)).collect::<String>()
172-
}),
166+
Self::Table(ref table) => {
167+
let mut s = String::new();
168+
for (k, v) in table.iter() {
169+
write!(s, "{} => {}, ", k, v)?
170+
}
171+
write!(f, "{{ {s} }}")
172+
}
173+
Self::Array(ref array) => {
174+
let mut s = String::new();
175+
for e in array.iter() {
176+
write!(s, "{}, ", e)?;
177+
}
178+
write!(f, "{s:?}")
179+
}
173180
}
174181
}
175182
}

0 commit comments

Comments
 (0)