Skip to main content

stellar_xdr/generated/
soroban_transaction_data_ext.rs

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