From 11464135bc894f0b4951967d3b059ade5df3a09d Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Sun, 12 Jun 2022 15:36:43 -0400 Subject: [PATCH] simplify to_chars_array --- Cargo.toml | 1 + src/unicode_helper.rs | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1858a60..00d989b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,7 @@ serde_json = "1" zstd = "0.11" run_script = "0.9" json5 = "0.4" +itertools = "0.10" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] instant = "0.1" diff --git a/src/unicode_helper.rs b/src/unicode_helper.rs index e5a2dea..8928f59 100644 --- a/src/unicode_helper.rs +++ b/src/unicode_helper.rs @@ -1,3 +1,5 @@ +use itertools::Itertools; + #[allow(dead_code)] pub fn to_unicode_hash(c: char) -> String { c.escape_unicode() @@ -15,16 +17,7 @@ pub fn to_chars_array(chars: Vec) -> String { &chars .iter() .map(|c| format!("'{}'", c.escape_unicode())) - .enumerate() - .map(|(i, x)| { - // Add comma and space if needed - match chars.len() > i + 1 { - true => x + ", ", - false => x, - } - }) - .collect::>() - .concat(), + .join(", "), "]", ] .concat()