Initial
This commit is contained in:
commit
284f099d3e
22 changed files with 1717 additions and 0 deletions
20
src/days/day01/mod.rs
Normal file
20
src/days/day01/mod.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use anyhow::Result;
|
||||
|
||||
use super::template::{DayTrait, ResultType};
|
||||
|
||||
pub struct Day;
|
||||
const DAY_NUMBER: usize = 1;
|
||||
|
||||
impl DayTrait for Day {
|
||||
fn get_day_number(&self) -> usize {
|
||||
DAY_NUMBER
|
||||
}
|
||||
|
||||
fn part1(&self, lines: String) -> Result<ResultType> {
|
||||
Ok(ResultType::NoResult)
|
||||
}
|
||||
|
||||
fn part2(&self, lines: String) -> Result<ResultType> {
|
||||
Ok(ResultType::NoResult)
|
||||
}
|
||||
}
|
||||
20
src/days/day__/mod.rs
Normal file
20
src/days/day__/mod.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use anyhow::Result;
|
||||
|
||||
use super::template::{Day, ResultType};
|
||||
|
||||
pub struct Day;
|
||||
const DAY_NUMBER: usize = 0;
|
||||
|
||||
impl DayTemplate for Day {
|
||||
fn get_day_number(&self) -> usize {
|
||||
DAY_NUMBER
|
||||
}
|
||||
|
||||
fn part1(&self, lines: String) -> Result<ResultType> {
|
||||
Ok(ResultType::NoResult)
|
||||
}
|
||||
|
||||
fn part2(&self, lines: String) -> Result<ResultType> {
|
||||
Ok(ResultType::NoResult)
|
||||
}
|
||||
}
|
||||
38
src/days/mod.rs
Normal file
38
src/days/mod.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use anyhow::Result;
|
||||
|
||||
use self::{day01::Day, template::DayTrait};
|
||||
use thiserror::Error;
|
||||
|
||||
pub use template::ResultType;
|
||||
|
||||
mod day01;
|
||||
mod template;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum TemplateError {
|
||||
#[error("Not a valid day number: {0}")]
|
||||
InvalidNumber(usize),
|
||||
}
|
||||
|
||||
pub struct DayProvider {
|
||||
days: Vec<Box<dyn DayTrait>>,
|
||||
}
|
||||
|
||||
impl DayProvider {
|
||||
pub fn create() -> DayProvider {
|
||||
DayProvider {
|
||||
days: vec![Box::new(Day)],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_day(&self, day_num: usize) -> Result<&Box<dyn DayTrait>> {
|
||||
Ok(self
|
||||
.days
|
||||
.get(day_num - 1)
|
||||
.ok_or(TemplateError::InvalidNumber(day_num))?)
|
||||
}
|
||||
|
||||
pub fn get_all_days(&self) -> &[Box<dyn DayTrait>] {
|
||||
&self.days
|
||||
}
|
||||
}
|
||||
14
src/days/template.rs
Normal file
14
src/days/template.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use anyhow::Result;
|
||||
|
||||
pub enum ResultType {
|
||||
IntResult(i64),
|
||||
StringResult(String),
|
||||
LinesResult(String),
|
||||
NoResult,
|
||||
}
|
||||
|
||||
pub trait DayTrait {
|
||||
fn get_day_number(&self) -> usize;
|
||||
fn part1(&self, lines: String) -> Result<ResultType>;
|
||||
fn part2(&self, lines: String) -> Result<ResultType>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue