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