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