From 4fc398e5a6c2aa2b49112026afa9618085f12707 Mon Sep 17 00:00:00 2001 From: Narthana Epa Date: Sat, 28 Sep 2024 12:41:09 +1000 Subject: [PATCH] Don't clone words before joining them --- src/passphrase.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/passphrase.rs b/src/passphrase.rs index 2beeb5e..3b840dc 100644 --- a/src/passphrase.rs +++ b/src/passphrase.rs @@ -7,6 +7,8 @@ pub fn new( num_words: usize, separator: &str, ) -> Result { + use itertools::Itertools; + if words.len() < num_words { return Err(eyre!( "Your dictionary only has {} suitable words, but you asked for {} words.", @@ -20,10 +22,7 @@ pub fn new( words.swap(i, j); }); - Ok((0..num_words) - .map(|i| words[i].clone()) - .collect::>() - .join(separator)) + Ok((0..num_words).map(|i| &words[i]).join(separator)) } #[cfg(test)]