This commit is contained in:
spectre 2023-12-04 01:00:28 +01:00
commit 1299527ab2
19 changed files with 1335 additions and 0 deletions

59
shared/src/answer.rs Normal file
View file

@ -0,0 +1,59 @@
use std::fmt::{self, Display, Formatter, write};
#[derive(PartialEq)]
pub enum Answer {
String(String),
Number(u64),
Float(f64),
Unimplemented,
}
impl Display for Answer {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Answer::String(s) => write!(f, "{s}"),
Answer::Number(n) => write!(f, "{n}"),
Answer::Float(d) => write!(f, "{d}"),
Answer::Unimplemented => write!(f, "Unimplemented"),
}
}
}
impl From<String> for Answer {
fn from(value: String) -> Self {
Self::String(value)
}
}
impl From<&str> for Answer {
fn from(value: &str) -> Self {
Self::String(value.to_string())
}
}
impl From<f64> for Answer {
fn from(value: f64) -> Self {
Self::Float(value)
}
}
impl From<f32> for Answer {
fn from(value: f32) -> Self {
Self::Float(value as f64)
}
}
macro_rules! impl_from_numeric {
($($type:ty),*) => {
$(
impl From<$type> for Answer {
fn from(item: $type) -> Self {
Answer::Number(item as u64)
}
}
)*
};
}
impl_from_numeric!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize);

0
shared/src/input_data.rs Normal file
View file

7
shared/src/lib.rs Normal file
View file

@ -0,0 +1,7 @@
mod answer;
mod input_data;
mod solution;
pub use answer::Answer;
pub use solution::Solution;

6
shared/src/solution.rs Normal file
View file

@ -0,0 +1,6 @@
use crate::Answer;
pub trait Solution {
fn part_1(&self, input: &str) -> Answer;
fn part_2(&self, input: &str) -> Answer;
}