Skip to main content

stellar_xdr/generated/
transaction_meta.rs

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