From e4c8d2f4a34af3def1576e29bcf72f7bf4aa877a Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Sat, 3 Jul 2021 17:31:36 -0500 Subject: [PATCH] Utilize Some/None return from slice::first() --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0a8a821..99789e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,11 @@ pub fn build_proverb(list: &[&str]) -> String { let mut verse = "".to_string(); - if !list.is_empty() { + if let Some(nail) = list.first() { for item in list.windows(2) { verse.push_str(&format!("For want of a {} the {} was lost.\n", item[0], item[1])); } - verse.push_str(&format!("And all for the want of a {}.", list[0])); + verse.push_str(&format!("And all for the want of a {}.", nail)); } verse