summaryrefslogtreecommitdiffstats
path: root/src/2020/7/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/2020/7/mod.rs')
-rw-r--r--src/2020/7/mod.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/2020/7/mod.rs b/src/2020/7/mod.rs
index 6199ad0..2c8a1a7 100644
--- a/src/2020/7/mod.rs
+++ b/src/2020/7/mod.rs
@@ -28,11 +28,7 @@ pub fn part2(graph: Graph) -> Result<i64> {
}
fn parse_line(line: &str) -> Result<(String, Vec<(i64, String)>)> {
- let main_rx = Regex::new(r"^(.*) bags contain (.*)\.$").unwrap();
- let contents_rx = Regex::new(r"^([0-9]+) (.*) bags?").unwrap();
-
- let captures = main_rx
- .captures(line)
+ let captures = regex_captures!(r"^(.*) bags contain (.*)\.$", line)
.context("line failed to match regex")?;
let color = captures.get(1).unwrap().as_str();
let contents = captures.get(2).unwrap().as_str();
@@ -44,9 +40,9 @@ fn parse_line(line: &str) -> Result<(String, Vec<(i64, String)>)> {
contents
.split(", ")
.map(|s| {
- let captures = contents_rx
- .captures(s)
- .context("line failed to match regex")?;
+ let captures =
+ regex_captures!(r"^([0-9]+) (.*) bags?", s)
+ .context("line failed to match regex")?;
Ok((
captures
.get(1)