From 000003708fca85c2b43b012a33c6e3dbaec488de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Thu, 23 Nov 2023 00:01:54 +0100 Subject: [PATCH] feat: move data files out of src/ --- .gitignore | 4 ++-- Cargo.lock | 6 +++--- Cargo.toml | 2 +- {src => data}/examples/.keep | 0 {src => data}/inputs/.keep | 0 src/lib.rs | 20 ++++++++++++-------- utils/scaffold/src/main.rs | 19 ++++++++----------- 7 files changed, 26 insertions(+), 25 deletions(-) rename {src => data}/examples/.keep (100%) rename {src => data}/inputs/.keep (100%) diff --git a/.gitignore b/.gitignore index fd16741..d27a910 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,6 @@ target/ .env # downloaded inputs -/src/inputs/* -!/src/inputs/.keep +/data/inputs/* +!/data/inputs/.keep diff --git a/Cargo.lock b/Cargo.lock index 3a103a7..b8dc33a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aoc" -version = "36.0.0" +version = "37.0.0" dependencies = [ "itertools", ] @@ -105,7 +105,7 @@ checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" [[package]] name = "download" -version = "36.0.0" +version = "37.0.0" dependencies = [ "dotenvy", "pico-args", @@ -643,7 +643,7 @@ checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "scaffold" -version = "36.0.0" +version = "37.0.0" dependencies = [ "dotenvy", "pico-args", diff --git a/Cargo.toml b/Cargo.toml index 98bdedc..6d0e6fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ members = ["utils/download", "utils/scaffold"] [workspace.package] description = "template for advent of code" readme = "README.md" -version = "36.0.0" +version = "37.0.0" edition = "2021" license = "MIT" authors = ["Matej JaneΕΎič "] diff --git a/src/examples/.keep b/data/examples/.keep similarity index 100% rename from src/examples/.keep rename to data/examples/.keep diff --git a/src/inputs/.keep b/data/inputs/.keep similarity index 100% rename from src/inputs/.keep rename to data/inputs/.keep diff --git a/src/lib.rs b/src/lib.rs index 7c6bcc4..e40402d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,8 @@ pub const ANSI_BOLD: &str = "\x1b[1m"; pub const ANSI_RESET: &str = "\x1b[0m"; #[macro_export] -macro_rules! solve { - ($part:expr, $solver:ident, $input:expr) => {{ +macro_rules! solution { + ($day:expr) => { use aoc::{ANSI_BOLD, ANSI_ITALIC, ANSI_RESET}; use std::fmt::Display; use std::time::Instant; @@ -34,16 +34,20 @@ macro_rules! solve { } } - println!("πŸŽ„ {}Part {}{} πŸŽ„", ANSI_BOLD, $part, ANSI_RESET); - print_result($solver, $input); - }}; + fn main() { + let input = aoc::read_file("inputs", 1); + println!("πŸŽ„ {}Part {}{} πŸŽ„", ANSI_BOLD, 1, ANSI_RESET); + print_result(part_one, &input); + println!("πŸŽ„ {}Part {}{} πŸŽ„", ANSI_BOLD, 1, ANSI_RESET); + print_result(part_two, &input); + } + }; } +#[must_use] pub fn read_file(folder: &str, day: u8) -> String { let cwd = env::current_dir().unwrap(); - - let filepath = cwd.join("src").join(folder).join(format!("{day:02}.txt")); - + let filepath = cwd.join("data").join(folder).join(format!("{day:02}.txt")); let f = fs::read_to_string(filepath); f.expect("could not open input file").trim().to_string() } diff --git a/utils/scaffold/src/main.rs b/utils/scaffold/src/main.rs index 430f60e..ff5c0f8 100644 --- a/utils/scaffold/src/main.rs +++ b/utils/scaffold/src/main.rs @@ -11,26 +11,23 @@ use std::{ const MODULE_TEMPLATE: &str = r#"pub fn part_one(input: &str) -> Option { None } + pub fn part_two(input: &str) -> Option { None } -fn main() { - let input = &aoc::read_file("inputs", DAY); - aoc::solve!(1, part_one, input); - aoc::solve!(2, part_two, input); -} + +aoc::solution!(DAY); + #[cfg(test)] mod tests { use super::*; #[test] fn test_part_one() { - let input = aoc::read_file("examples", DAY); - assert_eq!(part_one(&input), None); + assert_eq!(part_one(&aoc::read_file("examples", DAY)), None); } #[test] fn test_part_two() { - let input = aoc::read_file("examples", DAY); - assert_eq!(part_two(&input), None); + assert_eq!(part_two(&aoc::read_file("examples", DAY)), None); } } "#; @@ -59,8 +56,8 @@ fn main() { let day_padded = format!("{day:02}"); - let input_path = format!("src/inputs/{day_padded}.txt"); - let example_path = format!("src/examples/{day_padded}.txt"); + let input_path = format!("data/inputs/{day_padded}.txt"); + let example_path = format!("data/examples/{day_padded}.txt"); let module_path = format!("src/bin/{day_padded}.rs"); let mut file = match safe_create_file(&module_path) {