Skip to main content

stellar_xdr/generated/
inflation_result.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// InflationResult is an XDR Union defined as:
5///
6/// ```text
7/// union InflationResult switch (InflationResultCode code)
8/// {
9/// case INFLATION_SUCCESS:
10///     InflationPayout payouts<>;
11/// case INFLATION_NOT_TIME:
12///     void;
13/// };
14/// ```
15///
16// union with discriminant InflationResultCode
17#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
18#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
19#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
20#[cfg_attr(
21    all(feature = "serde", feature = "alloc"),
22    serde_with::serde_as,
23    derive(serde::Serialize, serde::Deserialize),
24    serde(rename_all = "snake_case")
25)]
26#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
27#[allow(clippy::large_enum_variant)]
28pub enum InflationResult {
29    Success(VecM<InflationPayout>),
30    NotTime,
31}
32
33#[cfg(feature = "alloc")]
34impl Default for InflationResult {
35    fn default() -> Self {
36        Self::Success(VecM::<InflationPayout>::default())
37    }
38}
39
40impl InflationResult {
41    const _VARIANTS: &[InflationResultCode] =
42        &[InflationResultCode::Success, InflationResultCode::NotTime];
43    pub const VARIANTS: [InflationResultCode; Self::_VARIANTS.len()] = {
44        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
45        let mut i = 1;
46        while i < Self::_VARIANTS.len() {
47            arr[i] = Self::_VARIANTS[i];
48            i += 1;
49        }
50        arr
51    };
52    const _VARIANTS_STR: &[&str] = &["Success", "NotTime"];
53    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
54        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
55        let mut i = 1;
56        while i < Self::_VARIANTS_STR.len() {
57            arr[i] = Self::_VARIANTS_STR[i];
58            i += 1;
59        }
60        arr
61    };
62
63    #[must_use]
64    pub const fn name(&self) -> &'static str {
65        match self {
66            Self::Success(_) => "Success",
67            Self::NotTime => "NotTime",
68        }
69    }
70
71    #[must_use]
72    pub const fn discriminant(&self) -> InflationResultCode {
73        #[allow(clippy::match_same_arms)]
74        match self {
75            Self::Success(_) => InflationResultCode::Success,
76            Self::NotTime => InflationResultCode::NotTime,
77        }
78    }
79
80    #[must_use]
81    pub const fn variants() -> [InflationResultCode; Self::_VARIANTS.len()] {
82        Self::VARIANTS
83    }
84}
85
86impl Name for InflationResult {
87    #[must_use]
88    fn name(&self) -> &'static str {
89        Self::name(self)
90    }
91}
92
93impl Discriminant<InflationResultCode> for InflationResult {
94    #[must_use]
95    fn discriminant(&self) -> InflationResultCode {
96        Self::discriminant(self)
97    }
98}
99
100impl Variants<InflationResultCode> for InflationResult {
101    fn variants() -> slice::Iter<'static, InflationResultCode> {
102        Self::VARIANTS.iter()
103    }
104}
105
106impl Union<InflationResultCode> for InflationResult {}
107
108impl ReadXdr for InflationResult {
109    #[cfg(feature = "std")]
110    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
111        r.with_limited_depth(|r| {
112            let dv: InflationResultCode = <InflationResultCode as ReadXdr>::read_xdr(r)?;
113            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
114            let v = match dv {
115                InflationResultCode::Success => {
116                    Self::Success(VecM::<InflationPayout>::read_xdr(r)?)
117                }
118                InflationResultCode::NotTime => Self::NotTime,
119                #[allow(unreachable_patterns)]
120                _ => return Err(Error::Invalid),
121            };
122            Ok(v)
123        })
124    }
125}
126
127impl WriteXdr for InflationResult {
128    #[cfg(feature = "std")]
129    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
130        w.with_limited_depth(|w| {
131            self.discriminant().write_xdr(w)?;
132            #[allow(clippy::match_same_arms)]
133            match self {
134                Self::Success(v) => v.write_xdr(w)?,
135                Self::NotTime => ().write_xdr(w)?,
136            };
137            Ok(())
138        })
139    }
140}