From c688a8e2e6fd699079f3f167539c93ae194fb69c Mon Sep 17 00:00:00 2001 From: Iwer Petersen Date: Mon, 23 Sep 2024 16:14:16 +0200 Subject: [PATCH 1/2] Fixes display string concatenation for array columns (["a", "b", "c"] was rendered "abc", now "{a, b, c}") --- src/database.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/database.rs b/src/database.rs index 0a81b5a..b809bf8 100644 --- a/src/database.rs +++ b/src/database.rs @@ -329,11 +329,14 @@ pub fn row_to_json(row: &PgRow) -> HashMap { } pub fn vec_to_string(vec: Vec) -> String { - vec.iter().fold(String::new(), |mut output, b| { - let s = b.to_string(); - let _ = write!(output, "{s}"); - output - }) + let mut content = String::new(); + for (i, elem) in vec.iter().enumerate() { + content.push_str(&*elem.to_string()); + if i != vec.len() - 1 { + content.push_str(", "); + } + } + String::from("{ ".to_owned() + &*content + &*" }".to_owned()) } pub fn row_to_vec(row: &PgRow) -> Vec { From 4833280017f11ddecf9cbe12157fcbbd7b1ffa05 Mon Sep 17 00:00:00 2001 From: Iwer Petersen Date: Mon, 23 Sep 2024 16:34:03 +0200 Subject: [PATCH 2/2] Applied clippy recommendations --- src/database.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database.rs b/src/database.rs index b809bf8..02cd955 100644 --- a/src/database.rs +++ b/src/database.rs @@ -331,12 +331,12 @@ pub fn row_to_json(row: &PgRow) -> HashMap { pub fn vec_to_string(vec: Vec) -> String { let mut content = String::new(); for (i, elem) in vec.iter().enumerate() { - content.push_str(&*elem.to_string()); + content.push_str(&elem.to_string()); if i != vec.len() - 1 { content.push_str(", "); } } - String::from("{ ".to_owned() + &*content + &*" }".to_owned()) + "{ ".to_owned() + &*content + &*" }".to_owned() } pub fn row_to_vec(row: &PgRow) -> Vec {