Hello there I am struggling a bit here with an AOC problem, the thing is that to read from a file I get an String but in order to use a Regex I need an &str. This is as far as I have reach right know I'm not really sure how to continue I have tried a few things but without any luck.
use std::env;
use anyhow::Context;
use aoc_common::load_input;
use regex::Regex;
fn main() -> anyhow::Result<()> {
let lines = load_input(env::args())
.expect("Unable to load input")
.map(|line| &*line) // <<<< The problem is here, since I can't borrow line and then return :/
.collect::<Vec<_>>();
let solution_p1: u16 = lines.clone().into_iter().get_solution_p1()?;
println!("Solution P1: {solution_p1}");
Ok(())
}
pub trait AOC {
fn get_solution_p1(self) -> anyhow::Result<u16>;
}
impl<'a, T: Iterator<Item = &'a str>> AOC for T {
fn get_solution_p1(self) -> anyhow::Result<u16> {
let game_regex = Regex::new(r"Game (\d+):")?;
self.map(|line| line).map(|line| {
game_regex
.captures(line)
.context("Unable to capture line using regex")
});
Ok(0)
}
}