Skip to main content

stellar_xdr/generated/
contract_event_body.rs

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