From b62fa53ed7196c5f63921a16813847af9bad2daa Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 3 Dec 2021 16:09:14 +0100 Subject: [PATCH] 2021: day02: no dirty unwraps --- aoc2021/src/day02.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aoc2021/src/day02.rs b/aoc2021/src/day02.rs index fbc1c2e..2bfc9c7 100644 --- a/aoc2021/src/day02.rs +++ b/aoc2021/src/day02.rs @@ -1,6 +1,6 @@ use std::fmt::Write; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; const INPUT: &str = include_str!("../input/day02.txt"); @@ -71,8 +71,8 @@ impl std::str::FromStr for Command { fn from_str(s: &str) -> Result { let mut split = s.split(' '); - let word = split.next().unwrap(); - let number = split.next().unwrap(); + let word = split.next().context("couldn't find word in command")?; + let number = split.next().context("couldn't find number in command")?; let number = number.parse()?;