Browse Source

Utilize Some/None return from slice::first()

master
Jim Infield 3 years ago
parent
commit
e4c8d2f4a3
  1. 4
      src/lib.rs

4
src/lib.rs

@ -1,11 +1,11 @@
pub fn build_proverb(list: &[&str]) -> String { pub fn build_proverb(list: &[&str]) -> String {
let mut verse = "".to_string(); let mut verse = "".to_string();
if !list.is_empty() {
if let Some(nail) = list.first() {
for item in list.windows(2) { 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!("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 verse

Loading…
Cancel
Save