Fix array formatting for SQL

This commit is contained in:
Elias Schriefer 2021-11-16 23:49:43 +01:00
parent 0d9631b6c4
commit 5c8e72a733

View File

@ -79,21 +79,24 @@ where
} }
#[inline] #[inline]
fn format_array_for_sql<T>(values: &[T]) -> String fn format_array_for_sql<I, T>(values: I) -> String
where where
T: Display I: IntoIterator<Item=T>,
T: Display,
{ {
match values.len() { let mut iter = values.into_iter();
1.. => {
let mut output = values[0].to_string(); let mut output = match iter.next() {
for v in &values[1..] { Some(first) => first.to_string(),
output += ","; None => return String::new(),
output += &v.to_string(); };
}
output for v in iter {
}, output += ",";
_ => values.first().map(|v| v.to_string()).unwrap_or(String::new()), output += &v.to_string();
} }
output
} }
#[inline] #[inline]