use serde::Deserialize;
use serde_with::{DisplayFromStr, serde_as};
pub type DriverID = String;
#[allow(clippy::doc_markdown)] pub type ConstructorID = String;
pub type CircuitID = String;
pub type StatusID = u32;
pub type SeasonID = u32;
pub type RoundID = u32;
#[serde_as]
#[derive(Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
pub struct RaceID {
#[serde_as(as = "DisplayFromStr")]
pub season: SeasonID,
#[serde_as(as = "DisplayFromStr")]
pub round: RoundID,
}
impl RaceID {
pub const fn from(season: SeasonID, round: RoundID) -> Self {
Self { season, round }
}
}
#[cfg(test)]
mod tests {
use crate::tests::asserts::*;
use shadow_asserts::{assert_eq, assert_ne};
use super::*;
#[test]
fn race_id_from_season_and_round() {
assert_eq!(RaceID { season: 2023, round: 1 }, RaceID::from(2023, 1));
assert_eq!(RaceID::from(2023, 1).season, 2023);
assert_eq!(RaceID::from(2023, 1).round, 1);
assert_eq!(RaceID::from(2023, 1), RaceID::from(2023, 1));
assert_ne!(RaceID::from(2023, 1), RaceID::from(2022, 1));
assert_ne!(RaceID::from(2023, 1), RaceID::from(2023, 2));
}
#[test]
fn race_id_deserialize() {
assert_eq!(
serde_json::from_str::<RaceID>(
r#"{
"season": "2023",
"round": "4"
}"#
)
.unwrap(),
RaceID::from(2023, 4)
);
}
}