Skip to main content

rubo4e/generated/v202607/
waermenutzung.rs

1#[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/// Wärmenutzung Marktlokation
10#[non_exhaustive]
11pub enum Waermenutzung {
12    #[cfg_attr(feature = "serde", serde(rename = "SPEICHERHEIZUNG"))]
13    #[cfg_attr(feature = "strum", strum(serialize = "SPEICHERHEIZUNG"))]
14    Speicherheizung,
15    #[cfg_attr(feature = "serde", serde(rename = "WAERMEPUMPE"))]
16    #[cfg_attr(feature = "strum", strum(serialize = "WAERMEPUMPE"))]
17    Waermepumpe,
18    #[cfg_attr(feature = "serde", serde(rename = "DIREKTHEIZUNG"))]
19    #[cfg_attr(feature = "strum", strum(serialize = "DIREKTHEIZUNG"))]
20    Direktheizung,
21    /// Unknown or future variant — produced when deserializing a value
22    /// that is not yet known to this version of the library.
23    #[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
24    #[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
25    Unknown,
26}
27impl Waermenutzung {
28    /// All variants defined by the BO4E schema, in declaration order.
29    ///
30    /// Excludes the forward-compatibility [`Waermenutzung::Unknown`] catch-all, so this
31    /// is exactly the set of values that appear on the wire.  Available **without**
32    /// the `strum` feature — use it to drift-guard SQL `CHECK` lists and mappings.
33    pub const VARIANTS: &'static [Self] = &[
34        Self::Speicherheizung,
35        Self::Waermepumpe,
36        Self::Direktheizung,
37    ];
38    /// Number of schema-defined variants (equal to `VARIANTS.len()`), excluding the
39    /// [`Waermenutzung::Unknown`] catch-all.  Stable for this schema version.
40    pub const COUNT: usize = Self::VARIANTS.len();
41    /// Returns an iterator over all **known** variants of `Waermenutzung`.
42    ///
43    /// Yields only variants that correspond to values defined in the BO4E schema
44    /// (i.e. [`Self::VARIANTS`]), never the [`Waermenutzung::Unknown`] catch-all.
45    /// Available **without** the `strum` feature.
46    ///
47    /// # Example
48    /// ```
49    /// # use rubo4e::current::Waermenutzung;
50    /// // Never yields the `Unknown` catch-all, so the count matches `COUNT`.
51    /// assert_eq!(Waermenutzung::iter_known().count(), Waermenutzung::COUNT);
52    /// assert!(Waermenutzung::iter_known().all(|v| v.is_known()));
53    /// ```
54    pub fn iter_known() -> impl Iterator<Item = Self> + Clone {
55        Self::VARIANTS.iter().copied()
56    }
57    /// Returns the canonical BO4E wire string (SCREAMING_SNAKE_CASE) for this value.
58    ///
59    /// [`Waermenutzung::Unknown`] renders as `"UNKNOWN"`, matching its serialized form.
60    pub const fn as_wire(&self) -> &'static str {
61        match self {
62            Self::Speicherheizung => "SPEICHERHEIZUNG",
63            Self::Waermepumpe => "WAERMEPUMPE",
64            Self::Direktheizung => "DIREKTHEIZUNG",
65            Self::Unknown => "UNKNOWN",
66        }
67    }
68    /// **Strictly** parses a BO4E wire string into a known variant.
69    ///
70    /// Unlike the lenient `serde` / [`FromStr`](std::str::FromStr) path — which maps
71    /// any unrecognized value (a typo, a legacy code, or a value from a newer schema)
72    /// to [`Waermenutzung::Unknown`] — this returns
73    /// [`Err`](crate::error::UnknownVariant) for values not defined in this schema
74    /// version, including the literal `"UNKNOWN"`.  Use it at the ingest boundary to
75    /// reject bad values instead of silently degrading them.
76    ///
77    /// # Example
78    /// ```
79    /// # use rubo4e::current::Waermenutzung;
80    /// assert_eq!(Waermenutzung::from_wire("SPEICHERHEIZUNG"), Ok(Waermenutzung::Speicherheizung));
81    /// // Out-of-schema values are rejected rather than degraded:
82    /// assert!(Waermenutzung::from_wire("NOT_A_REAL_VALUE").is_err());
83    /// // …including the `Unknown` catch-all's own wire spelling:
84    /// assert!(Waermenutzung::from_wire("UNKNOWN").is_err());
85    /// ```
86    pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
87        match s {
88            "SPEICHERHEIZUNG" => Ok(Self::Speicherheizung),
89            "WAERMEPUMPE" => Ok(Self::Waermepumpe),
90            "DIREKTHEIZUNG" => Ok(Self::Direktheizung),
91            other => Err(crate::error::UnknownVariant::new(other)),
92        }
93    }
94    /// Returns `true` if this value is the forward-compatibility
95    /// [`Waermenutzung::Unknown`] catch-all (an out-of-schema value).
96    pub const fn is_unknown(&self) -> bool {
97        matches!(self, Self::Unknown)
98    }
99    /// Returns `true` if this value is a known, schema-defined variant.
100    pub const fn is_known(&self) -> bool {
101        !self.is_unknown()
102    }
103}
104impl std::fmt::Display for Waermenutzung {
105    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106        f.write_str(self.as_wire())
107    }
108}
109impl AsRef<str> for Waermenutzung {
110    fn as_ref(&self) -> &str {
111        self.as_wire()
112    }
113}
114#[cfg(feature = "versioned")]
115impl crate::bo4e_enum_sealed::Sealed for Waermenutzung {}
116#[cfg(feature = "versioned")]
117impl crate::Bo4eEnum for Waermenutzung {
118    const VARIANTS: &'static [Self] = Self::VARIANTS;
119    const COUNT: usize = Self::COUNT;
120    fn as_wire(&self) -> &'static str {
121        Self::as_wire(self)
122    }
123    fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
124        Self::from_wire(s)
125    }
126    fn is_unknown(&self) -> bool {
127        Self::is_unknown(self)
128    }
129}
130#[cfg(feature = "versioned")]
131impl crate::Bo4eStrict for Waermenutzung {
132    fn collect_unknown_enums(&self, path: &str, out: &mut Vec<String>) {
133        if self.is_unknown() {
134            out.push(path.to_owned());
135        }
136    }
137}
138#[cfg(feature = "sqlx")]
139impl sqlx::Type<sqlx::Postgres> for Waermenutzung {
140    fn type_info() -> sqlx::postgres::PgTypeInfo {
141        <String as sqlx::Type<sqlx::Postgres>>::type_info()
142    }
143}
144/// Encodes as the canonical BO4E wire string, borrowed from `as_wire` — no
145/// intermediate `String` or `serde_json::Value` is allocated.
146#[cfg(feature = "sqlx")]
147impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Waermenutzung {
148    fn encode_by_ref(
149        &self,
150        buf: &mut <sqlx::Postgres as sqlx::Database>::ArgumentBuffer<'q>,
151    ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
152        let s: &str = self.as_wire();
153        <&str as sqlx::Encode<'q, sqlx::Postgres>>::encode_by_ref(&s, buf)
154    }
155}
156/// Decodes leniently, matching the `serde` path: a value the schema does not
157/// define becomes [`Waermenutzung::Unknown`] rather than a decode error, so a
158/// database row written by a newer schema version still reads back.
159///
160/// Use [`Waermenutzung::from_wire`] on a `String` column, or check
161/// [`Waermenutzung::is_known`], where out-of-schema values must be rejected.
162#[cfg(feature = "sqlx")]
163impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Waermenutzung {
164    fn decode(
165        value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
166    ) -> Result<Self, sqlx::error::BoxDynError> {
167        let s = <&str as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
168        Ok(Self::from_wire(s).unwrap_or(Self::Unknown))
169    }
170}
171/// Lets `Vec<Waermenutzung>` bind to a `TEXT[]` column.  Only this crate can
172/// provide it: the trait and the enum are both foreign to any consumer, so the
173/// orphan rule rules out a downstream impl.
174#[cfg(feature = "sqlx")]
175impl sqlx::postgres::PgHasArrayType for Waermenutzung {
176    fn array_type_info() -> sqlx::postgres::PgTypeInfo {
177        <String as sqlx::postgres::PgHasArrayType>::array_type_info()
178    }
179}
180#[cfg(test)]
181impl proptest::arbitrary::Arbitrary for Waermenutzung {
182    type Parameters = ();
183    type Strategy = proptest::strategy::BoxedStrategy<Self>;
184    fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
185        use proptest::prelude::*;
186        proptest::sample::select(Self::VARIANTS.to_vec()).boxed()
187    }
188}