51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
|
mod de;
|
||
|
mod fr;
|
||
|
mod us;
|
||
|
|
||
|
use std::{collections::HashMap, fmt::Display, hash::Hash};
|
||
|
|
||
|
use crate::{
|
||
|
countries::{de::GermanHolidays, fr::FrenchHolidays, us::USHolidays},
|
||
|
holiday::{Activity, Holiday},
|
||
|
};
|
||
|
|
||
|
trait CountryHolidays<T>
|
||
|
where
|
||
|
T: StateList,
|
||
|
{
|
||
|
/// Returns a Tuple consisting of the identifier for all states and the holiday days
|
||
|
fn new() -> (String, Vec<Holiday>);
|
||
|
}
|
||
|
|
||
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||
|
pub enum CountryCode {
|
||
|
DE,
|
||
|
US,
|
||
|
FR,
|
||
|
}
|
||
|
|
||
|
impl CountryCode {
|
||
|
pub(crate) fn get_holidays(&self) -> (String, Vec<Holiday>) {
|
||
|
match self {
|
||
|
CountryCode::DE => GermanHolidays::new(),
|
||
|
CountryCode::US => USHolidays::new(),
|
||
|
CountryCode::FR => FrenchHolidays::new(),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub(crate) trait StateList
|
||
|
where
|
||
|
Self: Sized + Display + Hash + Eq,
|
||
|
{
|
||
|
fn list(states: &[(Self, &[Activity])]) -> HashMap<String, Vec<Activity>> {
|
||
|
let mut map = HashMap::new();
|
||
|
for state in states {
|
||
|
map.insert(state.0.to_string(), state.1.to_vec());
|
||
|
}
|
||
|
map
|
||
|
}
|
||
|
|
||
|
fn all_states_identifier() -> String;
|
||
|
}
|