1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "alloc", derive(Default))]
34#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
35#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
36#[cfg_attr(
37 all(feature = "serde", feature = "alloc"),
38 derive(serde::Serialize, serde::Deserialize),
39 serde(rename_all = "snake_case")
40)]
41#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
42#[repr(i32)]
43pub enum ManageBuyOfferResultCode {
44 #[cfg_attr(feature = "alloc", default)]
45 Success = 0,
46 Malformed = -1,
47 SellNoTrust = -2,
48 BuyNoTrust = -3,
49 SellNotAuthorized = -4,
50 BuyNotAuthorized = -5,
51 LineFull = -6,
52 Underfunded = -7,
53 CrossSelf = -8,
54 SellNoIssuer = -9,
55 BuyNoIssuer = -10,
56 NotFound = -11,
57 LowReserve = -12,
58}
59
60impl ManageBuyOfferResultCode {
61 const _VARIANTS: &[ManageBuyOfferResultCode] = &[
62 ManageBuyOfferResultCode::Success,
63 ManageBuyOfferResultCode::Malformed,
64 ManageBuyOfferResultCode::SellNoTrust,
65 ManageBuyOfferResultCode::BuyNoTrust,
66 ManageBuyOfferResultCode::SellNotAuthorized,
67 ManageBuyOfferResultCode::BuyNotAuthorized,
68 ManageBuyOfferResultCode::LineFull,
69 ManageBuyOfferResultCode::Underfunded,
70 ManageBuyOfferResultCode::CrossSelf,
71 ManageBuyOfferResultCode::SellNoIssuer,
72 ManageBuyOfferResultCode::BuyNoIssuer,
73 ManageBuyOfferResultCode::NotFound,
74 ManageBuyOfferResultCode::LowReserve,
75 ];
76 pub const VARIANTS: [ManageBuyOfferResultCode; Self::_VARIANTS.len()] = {
77 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
78 let mut i = 1;
79 while i < Self::_VARIANTS.len() {
80 arr[i] = Self::_VARIANTS[i];
81 i += 1;
82 }
83 arr
84 };
85 const _VARIANTS_STR: &[&str] = &[
86 "Success",
87 "Malformed",
88 "SellNoTrust",
89 "BuyNoTrust",
90 "SellNotAuthorized",
91 "BuyNotAuthorized",
92 "LineFull",
93 "Underfunded",
94 "CrossSelf",
95 "SellNoIssuer",
96 "BuyNoIssuer",
97 "NotFound",
98 "LowReserve",
99 ];
100 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
101 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
102 let mut i = 1;
103 while i < Self::_VARIANTS_STR.len() {
104 arr[i] = Self::_VARIANTS_STR[i];
105 i += 1;
106 }
107 arr
108 };
109
110 #[must_use]
111 pub const fn name(&self) -> &'static str {
112 match self {
113 Self::Success => "Success",
114 Self::Malformed => "Malformed",
115 Self::SellNoTrust => "SellNoTrust",
116 Self::BuyNoTrust => "BuyNoTrust",
117 Self::SellNotAuthorized => "SellNotAuthorized",
118 Self::BuyNotAuthorized => "BuyNotAuthorized",
119 Self::LineFull => "LineFull",
120 Self::Underfunded => "Underfunded",
121 Self::CrossSelf => "CrossSelf",
122 Self::SellNoIssuer => "SellNoIssuer",
123 Self::BuyNoIssuer => "BuyNoIssuer",
124 Self::NotFound => "NotFound",
125 Self::LowReserve => "LowReserve",
126 }
127 }
128
129 #[must_use]
130 pub const fn variants() -> [ManageBuyOfferResultCode; Self::_VARIANTS.len()] {
131 Self::VARIANTS
132 }
133}
134
135impl Name for ManageBuyOfferResultCode {
136 #[must_use]
137 fn name(&self) -> &'static str {
138 Self::name(self)
139 }
140}
141
142impl Variants<ManageBuyOfferResultCode> for ManageBuyOfferResultCode {
143 fn variants() -> slice::Iter<'static, ManageBuyOfferResultCode> {
144 Self::VARIANTS.iter()
145 }
146}
147
148impl Enum for ManageBuyOfferResultCode {}
149
150impl fmt::Display for ManageBuyOfferResultCode {
151 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152 f.write_str(self.name())
153 }
154}
155
156impl TryFrom<i32> for ManageBuyOfferResultCode {
157 type Error = Error;
158
159 fn try_from(i: i32) -> Result<Self, Error> {
160 let e = match i {
161 0 => ManageBuyOfferResultCode::Success,
162 -1 => ManageBuyOfferResultCode::Malformed,
163 -2 => ManageBuyOfferResultCode::SellNoTrust,
164 -3 => ManageBuyOfferResultCode::BuyNoTrust,
165 -4 => ManageBuyOfferResultCode::SellNotAuthorized,
166 -5 => ManageBuyOfferResultCode::BuyNotAuthorized,
167 -6 => ManageBuyOfferResultCode::LineFull,
168 -7 => ManageBuyOfferResultCode::Underfunded,
169 -8 => ManageBuyOfferResultCode::CrossSelf,
170 -9 => ManageBuyOfferResultCode::SellNoIssuer,
171 -10 => ManageBuyOfferResultCode::BuyNoIssuer,
172 -11 => ManageBuyOfferResultCode::NotFound,
173 -12 => ManageBuyOfferResultCode::LowReserve,
174 #[allow(unreachable_patterns)]
175 _ => return Err(Error::Invalid),
176 };
177 Ok(e)
178 }
179}
180
181impl From<ManageBuyOfferResultCode> for i32 {
182 #[must_use]
183 fn from(e: ManageBuyOfferResultCode) -> Self {
184 e as Self
185 }
186}
187
188impl ReadXdr for ManageBuyOfferResultCode {
189 #[cfg(feature = "std")]
190 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
191 r.with_limited_depth(|r| {
192 let e = i32::read_xdr(r)?;
193 let v: Self = e.try_into()?;
194 Ok(v)
195 })
196 }
197}
198
199impl WriteXdr for ManageBuyOfferResultCode {
200 #[cfg(feature = "std")]
201 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
202 w.with_limited_depth(|w| {
203 let i: i32 = (*self).into();
204 i.write_xdr(w)
205 })
206 }
207}