holidays-rs/src/countries/mod.rs

65 lines
1.4 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>);
}
/// Represents country codes for holiday calculations
///
/// # Variants
/// * `DE` - Germany
/// * `US` - United States
/// * `FR` - France
///
/// # Purpose
/// Provides a type-safe way to specify countries for holiday-related operations
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum CountryCode {
/// Germany
DE,
/// The United States
US,
/// France
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;
}