Skip to content

Commit

Permalink
Fix clippy: Rewrite string building
Browse files Browse the repository at this point in the history
Clippy complained about how we build the strings here, so rewrite it.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
  • Loading branch information
matthiasbeyer committed Oct 6, 2023
1 parent 9f6b500 commit 316a603
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ where

impl Display for ValueKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::fmt::Write;

match *self {
Self::String(ref value) => write!(f, "{}", value),
Self::Boolean(value) => write!(f, "{}", value),
Expand All @@ -161,15 +163,20 @@ impl Display for ValueKind {
Self::U128(value) => write!(f, "{}", value),
Self::Float(value) => write!(f, "{}", value),
Self::Nil => write!(f, "nil"),
Self::Table(ref table) => write!(f, "{{ {} }}", {
table
.iter()
.map(|(k, v)| format!("{} => {}, ", k, v))
.collect::<String>()
}),
Self::Array(ref array) => write!(f, "{:?}", {
array.iter().map(|e| format!("{}, ", e)).collect::<String>()
}),
Self::Table(ref table) => {
let mut s = String::new();
for (k, v) in table.iter() {
write!(s, "{} => {}, ", k, v)?
}
write!(f, "{{ {s} }}")
},
Self::Array(ref array) => {
let mut s = String::new();
for e in array.iter() {
write!(s, "{}, ", e)?;
}
write!(f, "{s:?}")
},
}
}
}
Expand Down

0 comments on commit 316a603

Please sign in to comment.