github.com/mnlphlp/aoc22@v0.0.0-20230330151331-c1dc4bff1b9b/aoc22_rust/src/util.rs (about)

     1  use std::{fs::File, io::Read};
     2  
     3  pub fn read_input(day: usize, test: bool) -> String {
     4      let path = format!(
     5          "../day{day:0>2}/{}nput.txt",
     6          if test { "testI" } else { "i" }
     7      );
     8      let mut file = File::open(path).expect("File not found");
     9      let mut contents = String::new();
    10      file.read_to_string(&mut contents)
    11          .expect("Something went wrong reading the file");
    12      contents
    13  }