rubo4e/generated/v202607/
rollencodetyp.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 Rollencodetyp {
12 #[cfg_attr(feature = "serde", serde(rename = "BDEW"))]
13 #[cfg_attr(feature = "strum", strum(serialize = "BDEW"))]
14 Bdew,
15 #[cfg_attr(feature = "serde", serde(rename = "DVGW"))]
16 #[cfg_attr(feature = "strum", strum(serialize = "DVGW"))]
17 Dvgw,
18 #[cfg_attr(feature = "serde", serde(rename = "GLN"))]
19 #[cfg_attr(feature = "strum", strum(serialize = "GLN"))]
20 Gln,
21 #[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
24 #[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
25 Unknown,
26}
27impl Rollencodetyp {
28 pub const VARIANTS: &'static [Self] = &[Self::Bdew, Self::Dvgw, Self::Gln];
34 pub const COUNT: usize = Self::VARIANTS.len();
37 pub fn iter_known() -> impl Iterator<Item = Self> + Clone {
51 Self::VARIANTS.iter().copied()
52 }
53 pub const fn as_wire(&self) -> &'static str {
57 match self {
58 Self::Bdew => "BDEW",
59 Self::Dvgw => "DVGW",
60 Self::Gln => "GLN",
61 Self::Unknown => "UNKNOWN",
62 }
63 }
64 pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
83 match s {
84 "BDEW" => Ok(Self::Bdew),
85 "DVGW" => Ok(Self::Dvgw),
86 "GLN" => Ok(Self::Gln),
87 other => Err(crate::error::UnknownVariant::new(other)),
88 }
89 }
90 pub const fn is_unknown(&self) -> bool {
93 matches!(self, Self::Unknown)
94 }
95 pub const fn is_known(&self) -> bool {
97 !self.is_unknown()
98 }
99}
100impl std::fmt::Display for Rollencodetyp {
101 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
102 f.write_str(self.as_wire())
103 }
104}
105impl AsRef<str> for Rollencodetyp {
106 fn as_ref(&self) -> &str {
107 self.as_wire()
108 }
109}
110#[cfg(feature = "versioned")]
111impl crate::bo4e_enum_sealed::Sealed for Rollencodetyp {}
112#[cfg(feature = "versioned")]
113impl crate::Bo4eEnum for Rollencodetyp {
114 const VARIANTS: &'static [Self] = Self::VARIANTS;
115 const COUNT: usize = Self::COUNT;
116 fn as_wire(&self) -> &'static str {
117 Self::as_wire(self)
118 }
119 fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
120 Self::from_wire(s)
121 }
122 fn is_unknown(&self) -> bool {
123 Self::is_unknown(self)
124 }
125}
126#[cfg(feature = "versioned")]
127impl crate::Bo4eStrict for Rollencodetyp {
128 fn collect_unknown_enums(&self, path: &str, out: &mut Vec<String>) {
129 if self.is_unknown() {
130 out.push(path.to_owned());
131 }
132 }
133}
134#[cfg(feature = "sqlx")]
135impl sqlx::Type<sqlx::Postgres> for Rollencodetyp {
136 fn type_info() -> sqlx::postgres::PgTypeInfo {
137 <String as sqlx::Type<sqlx::Postgres>>::type_info()
138 }
139}
140#[cfg(feature = "sqlx")]
143impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Rollencodetyp {
144 fn encode_by_ref(
145 &self,
146 buf: &mut <sqlx::Postgres as sqlx::Database>::ArgumentBuffer<'q>,
147 ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
148 let s: &str = self.as_wire();
149 <&str as sqlx::Encode<'q, sqlx::Postgres>>::encode_by_ref(&s, buf)
150 }
151}
152#[cfg(feature = "sqlx")]
159impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Rollencodetyp {
160 fn decode(
161 value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
162 ) -> Result<Self, sqlx::error::BoxDynError> {
163 let s = <&str as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
164 Ok(Self::from_wire(s).unwrap_or(Self::Unknown))
165 }
166}
167#[cfg(feature = "sqlx")]
171impl sqlx::postgres::PgHasArrayType for Rollencodetyp {
172 fn array_type_info() -> sqlx::postgres::PgTypeInfo {
173 <String as sqlx::postgres::PgHasArrayType>::array_type_info()
174 }
175}
176#[cfg(test)]
177impl proptest::arbitrary::Arbitrary for Rollencodetyp {
178 type Parameters = ();
179 type Strategy = proptest::strategy::BoxedStrategy<Self>;
180 fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
181 use proptest::prelude::*;
182 proptest::sample::select(Self::VARIANTS.to_vec()).boxed()
183 }
184}