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