rubo4e/generated/v202607/
tariftyp.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3#[cfg_attr(
4 feature = "strum",
5 derive(strum::EnumString, strum::EnumIter, strum::IntoStaticStr)
6)]
7#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
8#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
9#[non_exhaustive]
11pub enum Tariftyp {
12 #[cfg_attr(feature = "serde", serde(rename = "GRUND_ERSATZVERSORGUNG"))]
13 #[cfg_attr(feature = "strum", strum(serialize = "GRUND_ERSATZVERSORGUNG"))]
14 GrundErsatzversorgung,
15 #[cfg_attr(feature = "serde", serde(rename = "GRUNDVERSORGUNG"))]
16 #[cfg_attr(feature = "strum", strum(serialize = "GRUNDVERSORGUNG"))]
17 Grundversorgung,
18 #[cfg_attr(feature = "serde", serde(rename = "ERSATZVERSORGUNG"))]
19 #[cfg_attr(feature = "strum", strum(serialize = "ERSATZVERSORGUNG"))]
20 Ersatzversorgung,
21 #[cfg_attr(feature = "serde", serde(rename = "SONDERTARIF"))]
22 #[cfg_attr(feature = "strum", strum(serialize = "SONDERTARIF"))]
23 Sondertarif,
24 #[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
27 #[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
28 Unknown,
29}
30impl Tariftyp {
31 pub const VARIANTS: &'static [Self] = &[
37 Self::GrundErsatzversorgung,
38 Self::Grundversorgung,
39 Self::Ersatzversorgung,
40 Self::Sondertarif,
41 ];
42 pub const COUNT: usize = Self::VARIANTS.len();
45 pub fn iter_known() -> impl Iterator<Item = Self> + Clone {
59 Self::VARIANTS.iter().copied()
60 }
61 pub const fn as_wire(&self) -> &'static str {
65 match self {
66 Self::GrundErsatzversorgung => "GRUND_ERSATZVERSORGUNG",
67 Self::Grundversorgung => "GRUNDVERSORGUNG",
68 Self::Ersatzversorgung => "ERSATZVERSORGUNG",
69 Self::Sondertarif => "SONDERTARIF",
70 Self::Unknown => "UNKNOWN",
71 }
72 }
73 pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
92 match s {
93 "GRUND_ERSATZVERSORGUNG" => Ok(Self::GrundErsatzversorgung),
94 "GRUNDVERSORGUNG" => Ok(Self::Grundversorgung),
95 "ERSATZVERSORGUNG" => Ok(Self::Ersatzversorgung),
96 "SONDERTARIF" => Ok(Self::Sondertarif),
97 other => Err(crate::error::UnknownVariant::new(other)),
98 }
99 }
100 pub const fn is_unknown(&self) -> bool {
103 matches!(self, Self::Unknown)
104 }
105 pub const fn is_known(&self) -> bool {
107 !self.is_unknown()
108 }
109}
110impl std::fmt::Display for Tariftyp {
111 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
112 f.write_str(self.as_wire())
113 }
114}
115impl AsRef<str> for Tariftyp {
116 fn as_ref(&self) -> &str {
117 self.as_wire()
118 }
119}
120#[cfg(feature = "versioned")]
121impl crate::bo4e_enum_sealed::Sealed for Tariftyp {}
122#[cfg(feature = "versioned")]
123impl crate::Bo4eEnum for Tariftyp {
124 const VARIANTS: &'static [Self] = Self::VARIANTS;
125 const COUNT: usize = Self::COUNT;
126 fn as_wire(&self) -> &'static str {
127 Self::as_wire(self)
128 }
129 fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
130 Self::from_wire(s)
131 }
132 fn is_unknown(&self) -> bool {
133 Self::is_unknown(self)
134 }
135}
136#[cfg(feature = "versioned")]
137impl crate::Bo4eStrict for Tariftyp {
138 fn collect_unknown_enums(&self, path: &str, out: &mut Vec<String>) {
139 if self.is_unknown() {
140 out.push(path.to_owned());
141 }
142 }
143}
144#[cfg(feature = "sqlx")]
145impl sqlx::Type<sqlx::Postgres> for Tariftyp {
146 fn type_info() -> sqlx::postgres::PgTypeInfo {
147 <String as sqlx::Type<sqlx::Postgres>>::type_info()
148 }
149}
150#[cfg(feature = "sqlx")]
153impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Tariftyp {
154 fn encode_by_ref(
155 &self,
156 buf: &mut <sqlx::Postgres as sqlx::Database>::ArgumentBuffer<'q>,
157 ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
158 let s: &str = self.as_wire();
159 <&str as sqlx::Encode<'q, sqlx::Postgres>>::encode_by_ref(&s, buf)
160 }
161}
162#[cfg(feature = "sqlx")]
169impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Tariftyp {
170 fn decode(
171 value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
172 ) -> Result<Self, sqlx::error::BoxDynError> {
173 let s = <&str as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
174 Ok(Self::from_wire(s).unwrap_or(Self::Unknown))
175 }
176}
177#[cfg(feature = "sqlx")]
181impl sqlx::postgres::PgHasArrayType for Tariftyp {
182 fn array_type_info() -> sqlx::postgres::PgTypeInfo {
183 <String as sqlx::postgres::PgHasArrayType>::array_type_info()
184 }
185}
186#[cfg(test)]
187impl proptest::arbitrary::Arbitrary for Tariftyp {
188 type Parameters = ();
189 type Strategy = proptest::strategy::BoxedStrategy<Self>;
190 fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
191 use proptest::prelude::*;
192 proptest::sample::select(Self::VARIANTS.to_vec()).boxed()
193 }
194}