1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::{
    fmt::{self, Display, Formatter},
    str::FromStr,
};

use chrono::NaiveDate;

use crate::error::ParseKeyError;

#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct LandSchluessel {
    pub land: u8,
}

impl LandSchluessel {
    pub fn new(land: u8) -> Self {
        Self { land }
    }
}

impl FromStr for LandSchluessel {
    type Err = ParseKeyError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if s.len() != 2 {
            return Err(ParseKeyError::invalid_length(s, 2));
        }

        let land = s.parse().map_err(|_| ParseKeyError::non_numeric(s))?;

        Ok(Self::new(land))
    }
}

impl Display for LandSchluessel {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{:02}", self.land)
    }
}

/// A Land (i.e. Bundesland, state) Daten.
#[derive(Clone, Debug)]
pub struct LandDaten {
    /// Timestamp
    pub gebietsstand: NaiveDate,

    /// Landschluessel
    pub schluessel: LandSchluessel,

    /// Name of Land (e.g. `Saarland`)
    pub name: String,

    /// Location of the government of this state.
    pub sitz_regierung: String,
}