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 39457c8 commit 4a530b8
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 4a530b8

Please sign in to comment.