bo4e_core/enums/
salutation.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
10#[cfg_attr(feature = "json-schema", schemars(rename = "Anrede"))]
11#[non_exhaustive]
12pub enum Salutation {
13 #[serde(rename = "HERR")]
15 Mr,
16
17 #[serde(rename = "FRAU")]
19 Ms,
20
21 #[serde(rename = "EHELEUTE")]
23 MarriedCouple,
24
25 #[serde(rename = "FIRMA")]
27 Company,
28
29 #[serde(rename = "FAMILIE")]
31 Family,
32
33 #[serde(rename = "ERBENGEMEINSCHAFT")]
35 HeirsCommunity,
36
37 #[serde(rename = "GRUNDSTUECKSGEMEINSCHAFT")]
39 PropertyCommunity,
40}
41
42impl Salutation {
43 pub fn german_name(&self) -> &'static str {
45 match self {
46 Self::Mr => "Herr",
47 Self::Ms => "Frau",
48 Self::MarriedCouple => "Eheleute",
49 Self::Company => "Firma",
50 Self::Family => "Familie",
51 Self::HeirsCommunity => "Erbengemeinschaft",
52 Self::PropertyCommunity => "Grundstuecksgemeinschaft",
53 }
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_serialize() {
63 assert_eq!(serde_json::to_string(&Salutation::Mr).unwrap(), r#""HERR""#);
64 assert_eq!(serde_json::to_string(&Salutation::Ms).unwrap(), r#""FRAU""#);
65 }
66
67 #[test]
68 fn test_deserialize() {
69 assert_eq!(
70 serde_json::from_str::<Salutation>(r#""HERR""#).unwrap(),
71 Salutation::Mr
72 );
73 assert_eq!(
74 serde_json::from_str::<Salutation>(r#""FIRMA""#).unwrap(),
75 Salutation::Company
76 );
77 }
78
79 #[test]
80 fn test_roundtrip() {
81 for salutation in [
82 Salutation::Mr,
83 Salutation::Ms,
84 Salutation::MarriedCouple,
85 Salutation::Company,
86 Salutation::Family,
87 Salutation::HeirsCommunity,
88 Salutation::PropertyCommunity,
89 ] {
90 let json = serde_json::to_string(&salutation).unwrap();
91 let parsed: Salutation = serde_json::from_str(&json).unwrap();
92 assert_eq!(salutation, parsed);
93 }
94 }
95}