stellar_xdr/generated/
invoke_host_function_result_code.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "alloc", derive(Default))]
23#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
24#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
25#[cfg_attr(
26 all(feature = "serde", feature = "alloc"),
27 derive(serde::Serialize, serde::Deserialize),
28 serde(rename_all = "snake_case")
29)]
30#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
31#[repr(i32)]
32pub enum InvokeHostFunctionResultCode {
33 #[cfg_attr(feature = "alloc", default)]
34 Success = 0,
35 Malformed = -1,
36 Trapped = -2,
37 ResourceLimitExceeded = -3,
38 EntryArchived = -4,
39 InsufficientRefundableFee = -5,
40}
41
42impl InvokeHostFunctionResultCode {
43 const _VARIANTS: &[InvokeHostFunctionResultCode] = &[
44 InvokeHostFunctionResultCode::Success,
45 InvokeHostFunctionResultCode::Malformed,
46 InvokeHostFunctionResultCode::Trapped,
47 InvokeHostFunctionResultCode::ResourceLimitExceeded,
48 InvokeHostFunctionResultCode::EntryArchived,
49 InvokeHostFunctionResultCode::InsufficientRefundableFee,
50 ];
51 pub const VARIANTS: [InvokeHostFunctionResultCode; 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 "Trapped",
64 "ResourceLimitExceeded",
65 "EntryArchived",
66 "InsufficientRefundableFee",
67 ];
68 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
69 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
70 let mut i = 1;
71 while i < Self::_VARIANTS_STR.len() {
72 arr[i] = Self::_VARIANTS_STR[i];
73 i += 1;
74 }
75 arr
76 };
77
78 #[must_use]
79 pub const fn name(&self) -> &'static str {
80 match self {
81 Self::Success => "Success",
82 Self::Malformed => "Malformed",
83 Self::Trapped => "Trapped",
84 Self::ResourceLimitExceeded => "ResourceLimitExceeded",
85 Self::EntryArchived => "EntryArchived",
86 Self::InsufficientRefundableFee => "InsufficientRefundableFee",
87 }
88 }
89
90 #[must_use]
91 pub const fn variants() -> [InvokeHostFunctionResultCode; Self::_VARIANTS.len()] {
92 Self::VARIANTS
93 }
94}
95
96impl Name for InvokeHostFunctionResultCode {
97 #[must_use]
98 fn name(&self) -> &'static str {
99 Self::name(self)
100 }
101}
102
103impl Variants<InvokeHostFunctionResultCode> for InvokeHostFunctionResultCode {
104 fn variants() -> slice::Iter<'static, InvokeHostFunctionResultCode> {
105 Self::VARIANTS.iter()
106 }
107}
108
109impl Enum for InvokeHostFunctionResultCode {}
110
111impl fmt::Display for InvokeHostFunctionResultCode {
112 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113 f.write_str(self.name())
114 }
115}
116
117impl TryFrom<i32> for InvokeHostFunctionResultCode {
118 type Error = Error;
119
120 fn try_from(i: i32) -> Result<Self, Error> {
121 let e = match i {
122 0 => InvokeHostFunctionResultCode::Success,
123 -1 => InvokeHostFunctionResultCode::Malformed,
124 -2 => InvokeHostFunctionResultCode::Trapped,
125 -3 => InvokeHostFunctionResultCode::ResourceLimitExceeded,
126 -4 => InvokeHostFunctionResultCode::EntryArchived,
127 -5 => InvokeHostFunctionResultCode::InsufficientRefundableFee,
128 #[allow(unreachable_patterns)]
129 _ => return Err(Error::Invalid),
130 };
131 Ok(e)
132 }
133}
134
135impl From<InvokeHostFunctionResultCode> for i32 {
136 #[must_use]
137 fn from(e: InvokeHostFunctionResultCode) -> Self {
138 e as Self
139 }
140}
141
142impl ReadXdr for InvokeHostFunctionResultCode {
143 #[cfg(feature = "std")]
144 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
145 r.with_limited_depth(|r| {
146 let e = i32::read_xdr(r)?;
147 let v: Self = e.try_into()?;
148 Ok(v)
149 })
150 }
151}
152
153impl WriteXdr for InvokeHostFunctionResultCode {
154 #[cfg(feature = "std")]
155 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
156 w.with_limited_depth(|w| {
157 let i: i32 = (*self).into();
158 i.write_xdr(w)
159 })
160 }
161}