Skip to main content

stellar_xdr/generated/
extend_footprint_ttl_result.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ExtendFootprintTtlResult is an XDR Union defined as:
5///
6/// ```text
7/// union ExtendFootprintTTLResult switch (ExtendFootprintTTLResultCode code)
8/// {
9/// case EXTEND_FOOTPRINT_TTL_SUCCESS:
10///     void;
11/// case EXTEND_FOOTPRINT_TTL_MALFORMED:
12/// case EXTEND_FOOTPRINT_TTL_RESOURCE_LIMIT_EXCEEDED:
13/// case EXTEND_FOOTPRINT_TTL_INSUFFICIENT_REFUNDABLE_FEE:
14///     void;
15/// };
16/// ```
17///
18// union with discriminant ExtendFootprintTtlResultCode
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 ExtendFootprintTtlResult {
31    Success,
32    Malformed,
33    ResourceLimitExceeded,
34    InsufficientRefundableFee,
35}
36
37#[cfg(feature = "alloc")]
38impl Default for ExtendFootprintTtlResult {
39    fn default() -> Self {
40        Self::Success
41    }
42}
43
44impl ExtendFootprintTtlResult {
45    const _VARIANTS: &[ExtendFootprintTtlResultCode] = &[
46        ExtendFootprintTtlResultCode::Success,
47        ExtendFootprintTtlResultCode::Malformed,
48        ExtendFootprintTtlResultCode::ResourceLimitExceeded,
49        ExtendFootprintTtlResultCode::InsufficientRefundableFee,
50    ];
51    pub const VARIANTS: [ExtendFootprintTtlResultCode; 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] = &[
61        "Success",
62        "Malformed",
63        "ResourceLimitExceeded",
64        "InsufficientRefundableFee",
65    ];
66    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
67        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
68        let mut i = 1;
69        while i < Self::_VARIANTS_STR.len() {
70            arr[i] = Self::_VARIANTS_STR[i];
71            i += 1;
72        }
73        arr
74    };
75
76    #[must_use]
77    pub const fn name(&self) -> &'static str {
78        match self {
79            Self::Success => "Success",
80            Self::Malformed => "Malformed",
81            Self::ResourceLimitExceeded => "ResourceLimitExceeded",
82            Self::InsufficientRefundableFee => "InsufficientRefundableFee",
83        }
84    }
85
86    #[must_use]
87    pub const fn discriminant(&self) -> ExtendFootprintTtlResultCode {
88        #[allow(clippy::match_same_arms)]
89        match self {
90            Self::Success => ExtendFootprintTtlResultCode::Success,
91            Self::Malformed => ExtendFootprintTtlResultCode::Malformed,
92            Self::ResourceLimitExceeded => ExtendFootprintTtlResultCode::ResourceLimitExceeded,
93            Self::InsufficientRefundableFee => {
94                ExtendFootprintTtlResultCode::InsufficientRefundableFee
95            }
96        }
97    }
98
99    #[must_use]
100    pub const fn variants() -> [ExtendFootprintTtlResultCode; Self::_VARIANTS.len()] {
101        Self::VARIANTS
102    }
103}
104
105impl Name for ExtendFootprintTtlResult {
106    #[must_use]
107    fn name(&self) -> &'static str {
108        Self::name(self)
109    }
110}
111
112impl Discriminant<ExtendFootprintTtlResultCode> for ExtendFootprintTtlResult {
113    #[must_use]
114    fn discriminant(&self) -> ExtendFootprintTtlResultCode {
115        Self::discriminant(self)
116    }
117}
118
119impl Variants<ExtendFootprintTtlResultCode> for ExtendFootprintTtlResult {
120    fn variants() -> slice::Iter<'static, ExtendFootprintTtlResultCode> {
121        Self::VARIANTS.iter()
122    }
123}
124
125impl Union<ExtendFootprintTtlResultCode> for ExtendFootprintTtlResult {}
126
127impl ReadXdr for ExtendFootprintTtlResult {
128    #[cfg(feature = "std")]
129    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
130        r.with_limited_depth(|r| {
131            let dv: ExtendFootprintTtlResultCode =
132                <ExtendFootprintTtlResultCode as ReadXdr>::read_xdr(r)?;
133            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
134            let v = match dv {
135                ExtendFootprintTtlResultCode::Success => Self::Success,
136                ExtendFootprintTtlResultCode::Malformed => Self::Malformed,
137                ExtendFootprintTtlResultCode::ResourceLimitExceeded => Self::ResourceLimitExceeded,
138                ExtendFootprintTtlResultCode::InsufficientRefundableFee => {
139                    Self::InsufficientRefundableFee
140                }
141                #[allow(unreachable_patterns)]
142                _ => return Err(Error::Invalid),
143            };
144            Ok(v)
145        })
146    }
147}
148
149impl WriteXdr for ExtendFootprintTtlResult {
150    #[cfg(feature = "std")]
151    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
152        w.with_limited_depth(|w| {
153            self.discriminant().write_xdr(w)?;
154            #[allow(clippy::match_same_arms)]
155            match self {
156                Self::Success => ().write_xdr(w)?,
157                Self::Malformed => ().write_xdr(w)?,
158                Self::ResourceLimitExceeded => ().write_xdr(w)?,
159                Self::InsufficientRefundableFee => ().write_xdr(w)?,
160            };
161            Ok(())
162        })
163    }
164}