Skip to content

Commit 9d06401

Browse files
authored
refactor: move Day struct to template module (#40)
1 parent 3260b73 commit 9d06401

File tree

12 files changed

+16
-21
lines changed

12 files changed

+16
-21
lines changed

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
mod day;
21
pub mod template;
3-
4-
pub use day::*;

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use advent_of_code::template::commands::{all, download, read, scaffold, solve};
22
use args::{parse, AppArguments};
33

44
mod args {
5+
use advent_of_code::template::Day;
56
use std::process;
67

7-
use advent_of_code::Day;
8-
98
pub enum AppArguments {
109
Download {
1110
day: Day,

src/template/aoc_cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
process::{Command, Output, Stdio},
55
};
66

7-
use crate::Day;
7+
use crate::template::Day;
88

99
#[derive(Debug)]
1010
pub enum AocCommandError {

src/template/commands/all.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::io;
22

33
use crate::template::{
4+
all_days,
45
readme_benchmarks::{self, Timings},
5-
ANSI_BOLD, ANSI_ITALIC, ANSI_RESET,
6+
Day, ANSI_BOLD, ANSI_ITALIC, ANSI_RESET,
67
};
7-
use crate::{all_days, Day};
88

99
pub fn handle(is_release: bool, is_timed: bool) {
1010
let mut timings: Vec<Timings> = vec![];
@@ -65,7 +65,7 @@ pub fn get_path_for_bin(day: Day) -> String {
6565
/// This module encapsulates interaction with these binaries, both invoking them as well as parsing the timing output.
6666
mod child_commands {
6767
use super::{get_path_for_bin, Error};
68-
use crate::Day;
68+
use crate::template::Day;
6969
use std::{
7070
io::{BufRead, BufReader},
7171
path::Path,

src/template/commands/download.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::template::aoc_cli;
2-
use crate::Day;
1+
use crate::template::{aoc_cli, Day};
32
use std::process;
43

54
pub fn handle(day: Day) {

src/template/commands/read.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::process;
22

3-
use crate::template::aoc_cli;
4-
use crate::Day;
3+
use crate::template::{aoc_cli, Day};
54

65
pub fn handle(day: Day) {
76
if aoc_cli::check().is_err() {

src/template/commands/scaffold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
process,
55
};
66

7-
use crate::Day;
7+
use crate::template::Day;
88

99
const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER);
1010

src/template/commands/solve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::process::{Command, Stdio};
22

3-
use crate::Day;
3+
use crate::template::Day;
44

55
pub fn handle(day: Day, release: bool, time: bool, submit_part: Option<u8>) {
66
let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()];

src/day.rs renamed to src/template/day.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ macro_rules! day {
126126
"`, expecting a value between 1 and 25"
127127
),
128128
);
129-
$crate::Day::__new_unchecked($day)
129+
$crate::template::Day::__new_unchecked($day)
130130
}};
131131
}
132132

src/template/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use crate::Day;
21
use std::{env, fs};
32

43
pub mod aoc_cli;
54
pub mod commands;
5+
mod day;
66
pub mod readme_benchmarks;
77
pub mod runner;
88

9+
pub use day::*;
10+
911
pub const ANSI_ITALIC: &str = "\x1b[3m";
1012
pub const ANSI_BOLD: &str = "\x1b[1m";
1113
pub const ANSI_RESET: &str = "\x1b[0m";
@@ -36,7 +38,7 @@ pub fn read_file_part(folder: &str, day: Day, part: u8) -> String {
3638
macro_rules! solution {
3739
($day:expr) => {
3840
/// The current day.
39-
const DAY: advent_of_code::Day = advent_of_code::day!($day);
41+
const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
4042

4143
fn main() {
4244
use advent_of_code::template::runner::*;

src/template/readme_benchmarks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// The approach taken is similar to how `aoc-readme-stars` handles this.
33
use std::{fs, io};
44

5-
use crate::Day;
5+
use crate::template::Day;
66

77
static MARKER: &str = "<!--- benchmarking table --->";
88

src/template/runner.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// Encapsulates code that interacts with solution functions.
2-
use crate::template::{aoc_cli, ANSI_ITALIC, ANSI_RESET};
3-
use crate::Day;
2+
use crate::template::{aoc_cli, Day, ANSI_ITALIC, ANSI_RESET};
43
use std::fmt::Display;
54
use std::io::{stdout, Write};
65
use std::process::Output;

0 commit comments

Comments
 (0)