initial
This commit is contained in:
commit
1299527ab2
19 changed files with 1335 additions and 0 deletions
6
shared/Cargo.toml
Normal file
6
shared/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "shared"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
59
shared/src/answer.rs
Normal file
59
shared/src/answer.rs
Normal 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
0
shared/src/input_data.rs
Normal file
7
shared/src/lib.rs
Normal file
7
shared/src/lib.rs
Normal 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
6
shared/src/solution.rs
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue