Skip to main content

stellar_xdr/generated/
contract_code_entry_ext.rs

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