holidays-rs/src/countries/mod.rs

65 lines
1.4 KiB
Rust
Raw Normal View History

2025-07-20 17:00:19 +00:00
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>);
}
2025-08-04 19:20:28 +00:00
/// 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
2025-07-20 17:00:19 +00:00
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum CountryCode {
2025-08-04 19:20:28 +00:00
/// Germany
2025-07-20 17:00:19 +00:00
DE,
2025-08-04 19:20:28 +00:00
/// The United States
2025-07-20 17:00:19 +00:00
US,
2025-08-04 19:20:28 +00:00
/// France
2025-07-20 17:00:19 +00:00
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;
}