advent_of_code_client/
cache.rs1use crate::Year;
3use std::{
4 fs,
5 path::{Path, PathBuf},
6};
7
8use super::Problem;
9
10pub fn store_input_in_cache(problem: Problem, input: &String) -> std::io::Result<()> {
11 fs::create_dir_all(get_input_cache_directory(problem.year()))?;
12 fs::write(get_input_cache_full_filename(problem), input)
13}
14
15pub fn get_input_cache_full_filename(problem: Problem) -> PathBuf {
16 Path::new(&get_input_cache_directory(problem.year()))
17 .join(format!("{day}.txt", day = problem.day()))
18}
19
20fn get_input_cache_directory(year: &Year) -> String {
22 format!(".input/{year}/", year = year.as_int())
23}