Skip to content

Commit

Permalink
refactor: move Day struct to template module
Browse files Browse the repository at this point in the history
  • Loading branch information
fspoettel committed Dec 2, 2023
1 parent 47e4f22 commit 0e00b6f
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 21 deletions.
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
mod day;
pub mod template;

pub use day::*;
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/template/aoc_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
process::{Command, Output, Stdio},
};

use crate::Day;
use crate::template::Day;

#[derive(Debug)]
pub enum AocCommandError {
Expand Down
6 changes: 3 additions & 3 deletions src/template/commands/all.rs
Original file line number Diff line number Diff line change
@@ -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<Timings> = vec![];
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/template/commands/download.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/template/commands/read.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/template/commands/scaffold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/template/commands/solve.rs
Original file line number Diff line number Diff line change
@@ -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<u8>) {
let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()];
Expand Down
2 changes: 1 addition & 1 deletion src/day.rs → src/template/day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}};
}

Expand Down
6 changes: 4 additions & 2 deletions src/template/mod.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion src/template/readme_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<!--- benchmarking table --->";

Expand Down
3 changes: 1 addition & 2 deletions src/template/runner.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 0e00b6f

Please sign in to comment.