From 5c8e72a733338667f0c79b800c8690b2124a5668 Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Tue, 16 Nov 2021 23:49:43 +0100 Subject: [PATCH] Fix array formatting for SQL --- src/graphql.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/graphql.rs b/src/graphql.rs index 11eaad1..bc80988 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -79,21 +79,24 @@ where } #[inline] -fn format_array_for_sql(values: &[T]) -> String +fn format_array_for_sql(values: I) -> String where - T: Display + I: IntoIterator, + 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]