gv100ad/model/
land.rs

1use std::{
2    fmt::{self, Display, Formatter},
3    str::FromStr,
4};
5
6use chrono::NaiveDate;
7
8use crate::error::ParseKeyError;
9
10#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
11pub struct LandSchluessel {
12    pub land: u8,
13}
14
15impl LandSchluessel {
16    pub fn new(land: u8) -> Self {
17        Self { land }
18    }
19}
20
21impl FromStr for LandSchluessel {
22    type Err = ParseKeyError;
23
24    fn from_str(s: &str) -> Result<Self, Self::Err> {
25        if s.len() != 2 {
26            return Err(ParseKeyError::invalid_length(s, 2));
27        }
28
29        let land = s.parse().map_err(|_| ParseKeyError::non_numeric(s))?;
30
31        Ok(Self::new(land))
32    }
33}
34
35impl Display for LandSchluessel {
36    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
37        write!(f, "{:02}", self.land)
38    }
39}
40
41/// A Land (i.e. Bundesland, state) Daten.
42#[derive(Clone, Debug)]
43pub struct LandDaten {
44    /// Timestamp
45    pub gebietsstand: NaiveDate,
46
47    /// Landschluessel
48    pub schluessel: LandSchluessel,
49
50    /// Name of Land (e.g. `Saarland`)
51    pub name: String,
52
53    /// Location of the government of this state.
54    pub sitz_regierung: String,
55}