From 0e00b6f5085605f8a73807ce71ce6e0c4dfc065a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=B6ttel?= <1682504+fspoettel@users.noreply.github.com> Date: Sat, 2 Dec 2023 22:50:43 +0100 Subject: [PATCH] refactor: move `Day` struct to `template` module --- src/lib.rs | 3 --- src/main.rs | 3 +-- src/template/aoc_cli.rs | 2 +- src/template/commands/all.rs | 6 +++--- src/template/commands/download.rs | 3 +-- src/template/commands/read.rs | 3 +-- src/template/commands/scaffold.rs | 2 +- src/template/commands/solve.rs | 2 +- src/{ => template}/day.rs | 2 +- src/template/mod.rs | 6 ++++-- src/template/readme_benchmarks.rs | 2 +- src/template/runner.rs | 3 +-- 12 files changed, 16 insertions(+), 21 deletions(-) rename src/{ => template}/day.rs (98%) diff --git a/src/lib.rs b/src/lib.rs index 04f64f0..612b5b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1 @@ -mod day; pub mod template; - -pub use day::*; diff --git a/src/main.rs b/src/main.rs index 23ba03c..8451fed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,9 @@ use advent_of_code::template::commands::{all, download, read, scaffold, solve}; use args::{parse, AppArguments}; mod args { + use advent_of_code::template::Day; use std::process; - use advent_of_code::Day; - pub enum AppArguments { Download { day: Day, diff --git a/src/template/aoc_cli.rs b/src/template/aoc_cli.rs index e7aab8b..a9ff3b0 100644 --- a/src/template/aoc_cli.rs +++ b/src/template/aoc_cli.rs @@ -4,7 +4,7 @@ use std::{ process::{Command, Output, Stdio}, }; -use crate::Day; +use crate::template::Day; #[derive(Debug)] pub enum AocCommandError { diff --git a/src/template/commands/all.rs b/src/template/commands/all.rs index 7443322..a183445 100644 --- a/src/template/commands/all.rs +++ b/src/template/commands/all.rs @@ -1,10 +1,10 @@ use std::io; use crate::template::{ + all_days, readme_benchmarks::{self, Timings}, - ANSI_BOLD, ANSI_ITALIC, ANSI_RESET, + Day, ANSI_BOLD, ANSI_ITALIC, ANSI_RESET, }; -use crate::{all_days, Day}; pub fn handle(is_release: bool, is_timed: bool) { let mut timings: Vec = vec![]; @@ -65,7 +65,7 @@ pub fn get_path_for_bin(day: Day) -> String { /// This module encapsulates interaction with these binaries, both invoking them as well as parsing the timing output. mod child_commands { use super::{get_path_for_bin, Error}; - use crate::Day; + use crate::template::Day; use std::{ io::{BufRead, BufReader}, path::Path, diff --git a/src/template/commands/download.rs b/src/template/commands/download.rs index 76ad635..9274f05 100644 --- a/src/template/commands/download.rs +++ b/src/template/commands/download.rs @@ -1,5 +1,4 @@ -use crate::template::aoc_cli; -use crate::Day; +use crate::template::{aoc_cli, Day}; use std::process; pub fn handle(day: Day) { diff --git a/src/template/commands/read.rs b/src/template/commands/read.rs index 01316f8..3e1a307 100644 --- a/src/template/commands/read.rs +++ b/src/template/commands/read.rs @@ -1,7 +1,6 @@ use std::process; -use crate::template::aoc_cli; -use crate::Day; +use crate::template::{aoc_cli, Day}; pub fn handle(day: Day) { if aoc_cli::check().is_err() { diff --git a/src/template/commands/scaffold.rs b/src/template/commands/scaffold.rs index 2a992bc..138e124 100644 --- a/src/template/commands/scaffold.rs +++ b/src/template/commands/scaffold.rs @@ -4,7 +4,7 @@ use std::{ process, }; -use crate::Day; +use crate::template::Day; const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER); diff --git a/src/template/commands/solve.rs b/src/template/commands/solve.rs index 50b7000..c2c3d89 100644 --- a/src/template/commands/solve.rs +++ b/src/template/commands/solve.rs @@ -1,6 +1,6 @@ use std::process::{Command, Stdio}; -use crate::Day; +use crate::template::Day; pub fn handle(day: Day, release: bool, time: bool, submit_part: Option) { let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()]; diff --git a/src/day.rs b/src/template/day.rs similarity index 98% rename from src/day.rs rename to src/template/day.rs index 5148797..fe1f66a 100644 --- a/src/day.rs +++ b/src/template/day.rs @@ -126,7 +126,7 @@ macro_rules! day { "`, expecting a value between 1 and 25" ), ); - $crate::Day::__new_unchecked($day) + $crate::template::Day::__new_unchecked($day) }}; } diff --git a/src/template/mod.rs b/src/template/mod.rs index d1533e1..3bbd505 100644 --- a/src/template/mod.rs +++ b/src/template/mod.rs @@ -1,11 +1,13 @@ -use crate::Day; use std::{env, fs}; pub mod aoc_cli; pub mod commands; +mod day; pub mod readme_benchmarks; pub mod runner; +pub use day::*; + pub const ANSI_ITALIC: &str = "\x1b[3m"; pub const ANSI_BOLD: &str = "\x1b[1m"; pub const ANSI_RESET: &str = "\x1b[0m"; @@ -36,7 +38,7 @@ pub fn read_file_part(folder: &str, day: Day, part: u8) -> String { macro_rules! solution { ($day:expr) => { /// The current day. - const DAY: advent_of_code::Day = advent_of_code::day!($day); + const DAY: advent_of_code::template::Day = advent_of_code::day!($day); fn main() { use advent_of_code::template::runner::*; diff --git a/src/template/readme_benchmarks.rs b/src/template/readme_benchmarks.rs index c564aa4..b282196 100644 --- a/src/template/readme_benchmarks.rs +++ b/src/template/readme_benchmarks.rs @@ -2,7 +2,7 @@ /// The approach taken is similar to how `aoc-readme-stars` handles this. use std::{fs, io}; -use crate::Day; +use crate::template::Day; static MARKER: &str = ""; diff --git a/src/template/runner.rs b/src/template/runner.rs index 5e6a9b3..00637bb 100644 --- a/src/template/runner.rs +++ b/src/template/runner.rs @@ -1,6 +1,5 @@ /// Encapsulates code that interacts with solution functions. -use crate::template::{aoc_cli, ANSI_ITALIC, ANSI_RESET}; -use crate::Day; +use crate::template::{aoc_cli, Day, ANSI_ITALIC, ANSI_RESET}; use std::fmt::Display; use std::io::{stdout, Write}; use std::process::Output;