Skip to main content

stellar_xdr/generated/
ledger_header_history_entry_ext.rs

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