Skip to main content

stellar_xdr/generated/
extend_footprint_ttl_result_code.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ExtendFootprintTtlResultCode is an XDR Enum defined as:
5///
6/// ```text
7/// enum ExtendFootprintTTLResultCode
8/// {
9///     // codes considered as "success" for the operation
10///     EXTEND_FOOTPRINT_TTL_SUCCESS = 0,
11///
12///     // codes considered as "failure" for the operation
13///     EXTEND_FOOTPRINT_TTL_MALFORMED = -1,
14///     EXTEND_FOOTPRINT_TTL_RESOURCE_LIMIT_EXCEEDED = -2,
15///     EXTEND_FOOTPRINT_TTL_INSUFFICIENT_REFUNDABLE_FEE = -3
16/// };
17/// ```
18///
19// enum
20#[cfg_attr(feature = "alloc", derive(Default))]
21#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
22#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
23#[cfg_attr(
24    all(feature = "serde", feature = "alloc"),
25    derive(serde::Serialize, serde::Deserialize),
26    serde(rename_all = "snake_case")
27)]
28#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
29#[repr(i32)]
30pub enum ExtendFootprintTtlResultCode {
31    #[cfg_attr(feature = "alloc", default)]
32    Success = 0,
33    Malformed = -1,
34    ResourceLimitExceeded = -2,
35    InsufficientRefundableFee = -3,
36}
37
38impl ExtendFootprintTtlResultCode {
39    const _VARIANTS: &[ExtendFootprintTtlResultCode] = &[
40        ExtendFootprintTtlResultCode::Success,
41        ExtendFootprintTtlResultCode::Malformed,
42        ExtendFootprintTtlResultCode::ResourceLimitExceeded,
43        ExtendFootprintTtlResultCode::InsufficientRefundableFee,
44    ];
45    pub const VARIANTS: [ExtendFootprintTtlResultCode; Self::_VARIANTS.len()] = {
46        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
47        let mut i = 1;
48        while i < Self::_VARIANTS.len() {
49            arr[i] = Self::_VARIANTS[i];
50            i += 1;
51        }
52        arr
53    };
54    const _VARIANTS_STR: &[&str] = &[
55        "Success",
56        "Malformed",
57        "ResourceLimitExceeded",
58        "InsufficientRefundableFee",
59    ];
60    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
61        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
62        let mut i = 1;
63        while i < Self::_VARIANTS_STR.len() {
64            arr[i] = Self::_VARIANTS_STR[i];
65            i += 1;
66        }
67        arr
68    };
69
70    #[must_use]
71    pub const fn name(&self) -> &'static str {
72        match self {
73            Self::Success => "Success",
74            Self::Malformed => "Malformed",
75            Self::ResourceLimitExceeded => "ResourceLimitExceeded",
76            Self::InsufficientRefundableFee => "InsufficientRefundableFee",
77        }
78    }
79
80    #[must_use]
81    pub const fn variants() -> [ExtendFootprintTtlResultCode; Self::_VARIANTS.len()] {
82        Self::VARIANTS
83    }
84}
85
86impl Name for ExtendFootprintTtlResultCode {
87    #[must_use]
88    fn name(&self) -> &'static str {
89        Self::name(self)
90    }
91}
92
93impl Variants<ExtendFootprintTtlResultCode> for ExtendFootprintTtlResultCode {
94    fn variants() -> slice::Iter<'static, ExtendFootprintTtlResultCode> {
95        Self::VARIANTS.iter()
96    }
97}
98
99impl Enum for ExtendFootprintTtlResultCode {}
100
101impl fmt::Display for ExtendFootprintTtlResultCode {
102    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103        f.write_str(self.name())
104    }
105}
106
107impl TryFrom<i32> for ExtendFootprintTtlResultCode {
108    type Error = Error;
109
110    fn try_from(i: i32) -> Result<Self, Error> {
111        let e = match i {
112            0 => ExtendFootprintTtlResultCode::Success,
113            -1 => ExtendFootprintTtlResultCode::Malformed,
114            -2 => ExtendFootprintTtlResultCode::ResourceLimitExceeded,
115            -3 => ExtendFootprintTtlResultCode::InsufficientRefundableFee,
116            #[allow(unreachable_patterns)]
117            _ => return Err(Error::Invalid),
118        };
119        Ok(e)
120    }
121}
122
123impl From<ExtendFootprintTtlResultCode> for i32 {
124    #[must_use]
125    fn from(e: ExtendFootprintTtlResultCode) -> Self {
126        e as Self
127    }
128}
129
130impl ReadXdr for ExtendFootprintTtlResultCode {
131    #[cfg(feature = "std")]
132    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
133        r.with_limited_depth(|r| {
134            let e = i32::read_xdr(r)?;
135            let v: Self = e.try_into()?;
136            Ok(v)
137        })
138    }
139}
140
141impl WriteXdr for ExtendFootprintTtlResultCode {
142    #[cfg(feature = "std")]
143    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
144        w.with_limited_depth(|w| {
145            let i: i32 = (*self).into();
146            i.write_xdr(w)
147        })
148    }
149}