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