refactor: move Day struct to template module (#40)

This commit is contained in:
Felix Spöttel 2023-12-05 22:39:20 +01:00 committed by GitHub
parent 3260b731be
commit 9d064019c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 16 additions and 21 deletions

View file

@ -1,4 +1 @@
mod day;
pub mod template; pub mod template;
pub use day::*;

View file

@ -2,10 +2,9 @@ use advent_of_code::template::commands::{all, download, read, scaffold, solve};
use args::{parse, AppArguments}; use args::{parse, AppArguments};
mod args { mod args {
use advent_of_code::template::Day;
use std::process; use std::process;
use advent_of_code::Day;
pub enum AppArguments { pub enum AppArguments {
Download { Download {
day: Day, day: Day,

View file

@ -4,7 +4,7 @@ use std::{
process::{Command, Output, Stdio}, process::{Command, Output, Stdio},
}; };
use crate::Day; use crate::template::Day;
#[derive(Debug)] #[derive(Debug)]
pub enum AocCommandError { pub enum AocCommandError {

View file

@ -1,10 +1,10 @@
use std::io; use std::io;
use crate::template::{ use crate::template::{
all_days,
readme_benchmarks::{self, Timings}, 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) { pub fn handle(is_release: bool, is_timed: bool) {
let mut timings: Vec<Timings> = vec![]; let mut timings: Vec<Timings> = 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. /// This module encapsulates interaction with these binaries, both invoking them as well as parsing the timing output.
mod child_commands { mod child_commands {
use super::{get_path_for_bin, Error}; use super::{get_path_for_bin, Error};
use crate::Day; use crate::template::Day;
use std::{ use std::{
io::{BufRead, BufReader}, io::{BufRead, BufReader},
path::Path, path::Path,

View file

@ -1,5 +1,4 @@
use crate::template::aoc_cli; use crate::template::{aoc_cli, Day};
use crate::Day;
use std::process; use std::process;
pub fn handle(day: Day) { pub fn handle(day: Day) {

View file

@ -1,7 +1,6 @@
use std::process; use std::process;
use crate::template::aoc_cli; use crate::template::{aoc_cli, Day};
use crate::Day;
pub fn handle(day: Day) { pub fn handle(day: Day) {
if aoc_cli::check().is_err() { if aoc_cli::check().is_err() {

View file

@ -4,7 +4,7 @@ use std::{
process, process,
}; };
use crate::Day; use crate::template::Day;
const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER); const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER);

View file

@ -1,6 +1,6 @@
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::Day; use crate::template::Day;
pub fn handle(day: Day, release: bool, time: bool, submit_part: Option<u8>) { pub fn handle(day: Day, release: bool, time: bool, submit_part: Option<u8>) {
let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()]; let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()];

View file

@ -126,7 +126,7 @@ macro_rules! day {
"`, expecting a value between 1 and 25" "`, expecting a value between 1 and 25"
), ),
); );
$crate::Day::__new_unchecked($day) $crate::template::Day::__new_unchecked($day)
}}; }};
} }

View file

@ -1,11 +1,13 @@
use crate::Day;
use std::{env, fs}; use std::{env, fs};
pub mod aoc_cli; pub mod aoc_cli;
pub mod commands; pub mod commands;
mod day;
pub mod readme_benchmarks; pub mod readme_benchmarks;
pub mod runner; pub mod runner;
pub use day::*;
pub const ANSI_ITALIC: &str = "\x1b[3m"; pub const ANSI_ITALIC: &str = "\x1b[3m";
pub const ANSI_BOLD: &str = "\x1b[1m"; pub const ANSI_BOLD: &str = "\x1b[1m";
pub const ANSI_RESET: &str = "\x1b[0m"; 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 { macro_rules! solution {
($day:expr) => { ($day:expr) => {
/// The current day. /// 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() { fn main() {
use advent_of_code::template::runner::*; use advent_of_code::template::runner::*;

View file

@ -2,7 +2,7 @@
/// The approach taken is similar to how `aoc-readme-stars` handles this. /// The approach taken is similar to how `aoc-readme-stars` handles this.
use std::{fs, io}; use std::{fs, io};
use crate::Day; use crate::template::Day;
static MARKER: &str = "<!--- benchmarking table --->"; static MARKER: &str = "<!--- benchmarking table --->";

View file

@ -1,6 +1,5 @@
/// Encapsulates code that interacts with solution functions. /// Encapsulates code that interacts with solution functions.
use crate::template::{aoc_cli, ANSI_ITALIC, ANSI_RESET}; use crate::template::{aoc_cli, Day, ANSI_ITALIC, ANSI_RESET};
use crate::Day;
use std::fmt::Display; use std::fmt::Display;
use std::io::{stdout, Write}; use std::io::{stdout, Write};
use std::process::Output; use std::process::Output;