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