diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2023-10-06 15:09:18 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2023-10-06 15:54:11 +0200 |
commit | 4a530b8d4f270ff97acf1187e1e860fe5af09397 (patch) | |
tree | 08edf4c5390c5f24b442060d2ffa63e32f44b20c /src/value.rs | |
parent | 39457c8a00aa315ddcec62930037c364d98fdfc7 (diff) |
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>
Diffstat (limited to 'src/value.rs')
-rw-r--r-- | src/value.rs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/value.rs b/src/value.rs index cd7440d..fe00e7e 100644 --- a/src/value.rs +++ b/src/value.rs @@ -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), @@ -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:?}") + } } } } |