Skip to main content

stellar_xdr/generated/
path_payment_strict_send_result.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// PathPaymentStrictSendResult is an XDR Union defined as:
5///
6/// ```text
7/// union PathPaymentStrictSendResult switch (PathPaymentStrictSendResultCode code)
8/// {
9/// case PATH_PAYMENT_STRICT_SEND_SUCCESS:
10///     struct
11///     {
12///         ClaimAtom offers<>;
13///         SimplePaymentResult last;
14///     } success;
15/// case PATH_PAYMENT_STRICT_SEND_MALFORMED:
16/// case PATH_PAYMENT_STRICT_SEND_UNDERFUNDED:
17/// case PATH_PAYMENT_STRICT_SEND_SRC_NO_TRUST:
18/// case PATH_PAYMENT_STRICT_SEND_SRC_NOT_AUTHORIZED:
19/// case PATH_PAYMENT_STRICT_SEND_NO_DESTINATION:
20/// case PATH_PAYMENT_STRICT_SEND_NO_TRUST:
21/// case PATH_PAYMENT_STRICT_SEND_NOT_AUTHORIZED:
22/// case PATH_PAYMENT_STRICT_SEND_LINE_FULL:
23///     void;
24/// case PATH_PAYMENT_STRICT_SEND_NO_ISSUER:
25///     Asset noIssuer; // the asset that caused the error
26/// case PATH_PAYMENT_STRICT_SEND_TOO_FEW_OFFERS:
27/// case PATH_PAYMENT_STRICT_SEND_OFFER_CROSS_SELF:
28/// case PATH_PAYMENT_STRICT_SEND_UNDER_DESTMIN:
29///     void;
30/// };
31/// ```
32///
33// union with discriminant PathPaymentStrictSendResultCode
34#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
35#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
36#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
37#[cfg_attr(
38    all(feature = "serde", feature = "alloc"),
39    serde_with::serde_as,
40    derive(serde::Serialize, serde::Deserialize),
41    serde(rename_all = "snake_case")
42)]
43#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
44#[allow(clippy::large_enum_variant)]
45pub enum PathPaymentStrictSendResult {
46    Success(PathPaymentStrictSendResultSuccess),
47    Malformed,
48    Underfunded,
49    SrcNoTrust,
50    SrcNotAuthorized,
51    NoDestination,
52    NoTrust,
53    NotAuthorized,
54    LineFull,
55    NoIssuer(Asset),
56    TooFewOffers,
57    OfferCrossSelf,
58    UnderDestmin,
59}
60
61#[cfg(feature = "alloc")]
62impl Default for PathPaymentStrictSendResult {
63    fn default() -> Self {
64        Self::Success(PathPaymentStrictSendResultSuccess::default())
65    }
66}
67
68impl PathPaymentStrictSendResult {
69    const _VARIANTS: &[PathPaymentStrictSendResultCode] = &[
70        PathPaymentStrictSendResultCode::Success,
71        PathPaymentStrictSendResultCode::Malformed,
72        PathPaymentStrictSendResultCode::Underfunded,
73        PathPaymentStrictSendResultCode::SrcNoTrust,
74        PathPaymentStrictSendResultCode::SrcNotAuthorized,
75        PathPaymentStrictSendResultCode::NoDestination,
76        PathPaymentStrictSendResultCode::NoTrust,
77        PathPaymentStrictSendResultCode::NotAuthorized,
78        PathPaymentStrictSendResultCode::LineFull,
79        PathPaymentStrictSendResultCode::NoIssuer,
80        PathPaymentStrictSendResultCode::TooFewOffers,
81        PathPaymentStrictSendResultCode::OfferCrossSelf,
82        PathPaymentStrictSendResultCode::UnderDestmin,
83    ];
84    pub const VARIANTS: [PathPaymentStrictSendResultCode; Self::_VARIANTS.len()] = {
85        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
86        let mut i = 1;
87        while i < Self::_VARIANTS.len() {
88            arr[i] = Self::_VARIANTS[i];
89            i += 1;
90        }
91        arr
92    };
93    const _VARIANTS_STR: &[&str] = &[
94        "Success",
95        "Malformed",
96        "Underfunded",
97        "SrcNoTrust",
98        "SrcNotAuthorized",
99        "NoDestination",
100        "NoTrust",
101        "NotAuthorized",
102        "LineFull",
103        "NoIssuer",
104        "TooFewOffers",
105        "OfferCrossSelf",
106        "UnderDestmin",
107    ];
108    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
109        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
110        let mut i = 1;
111        while i < Self::_VARIANTS_STR.len() {
112            arr[i] = Self::_VARIANTS_STR[i];
113            i += 1;
114        }
115        arr
116    };
117
118    #[must_use]
119    pub const fn name(&self) -> &'static str {
120        match self {
121            Self::Success(_) => "Success",
122            Self::Malformed => "Malformed",
123            Self::Underfunded => "Underfunded",
124            Self::SrcNoTrust => "SrcNoTrust",
125            Self::SrcNotAuthorized => "SrcNotAuthorized",
126            Self::NoDestination => "NoDestination",
127            Self::NoTrust => "NoTrust",
128            Self::NotAuthorized => "NotAuthorized",
129            Self::LineFull => "LineFull",
130            Self::NoIssuer(_) => "NoIssuer",
131            Self::TooFewOffers => "TooFewOffers",
132            Self::OfferCrossSelf => "OfferCrossSelf",
133            Self::UnderDestmin => "UnderDestmin",
134        }
135    }
136
137    #[must_use]
138    pub const fn discriminant(&self) -> PathPaymentStrictSendResultCode {
139        #[allow(clippy::match_same_arms)]
140        match self {
141            Self::Success(_) => PathPaymentStrictSendResultCode::Success,
142            Self::Malformed => PathPaymentStrictSendResultCode::Malformed,
143            Self::Underfunded => PathPaymentStrictSendResultCode::Underfunded,
144            Self::SrcNoTrust => PathPaymentStrictSendResultCode::SrcNoTrust,
145            Self::SrcNotAuthorized => PathPaymentStrictSendResultCode::SrcNotAuthorized,
146            Self::NoDestination => PathPaymentStrictSendResultCode::NoDestination,
147            Self::NoTrust => PathPaymentStrictSendResultCode::NoTrust,
148            Self::NotAuthorized => PathPaymentStrictSendResultCode::NotAuthorized,
149            Self::LineFull => PathPaymentStrictSendResultCode::LineFull,
150            Self::NoIssuer(_) => PathPaymentStrictSendResultCode::NoIssuer,
151            Self::TooFewOffers => PathPaymentStrictSendResultCode::TooFewOffers,
152            Self::OfferCrossSelf => PathPaymentStrictSendResultCode::OfferCrossSelf,
153            Self::UnderDestmin => PathPaymentStrictSendResultCode::UnderDestmin,
154        }
155    }
156
157    #[must_use]
158    pub const fn variants() -> [PathPaymentStrictSendResultCode; Self::_VARIANTS.len()] {
159        Self::VARIANTS
160    }
161}
162
163impl Name for PathPaymentStrictSendResult {
164    #[must_use]
165    fn name(&self) -> &'static str {
166        Self::name(self)
167    }
168}
169
170impl Discriminant<PathPaymentStrictSendResultCode> for PathPaymentStrictSendResult {
171    #[must_use]
172    fn discriminant(&self) -> PathPaymentStrictSendResultCode {
173        Self::discriminant(self)
174    }
175}
176
177impl Variants<PathPaymentStrictSendResultCode> for PathPaymentStrictSendResult {
178    fn variants() -> slice::Iter<'static, PathPaymentStrictSendResultCode> {
179        Self::VARIANTS.iter()
180    }
181}
182
183impl Union<PathPaymentStrictSendResultCode> for PathPaymentStrictSendResult {}
184
185impl ReadXdr for PathPaymentStrictSendResult {
186    #[cfg(feature = "std")]
187    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
188        r.with_limited_depth(|r| {
189            let dv: PathPaymentStrictSendResultCode =
190                <PathPaymentStrictSendResultCode as ReadXdr>::read_xdr(r)?;
191            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
192            let v = match dv {
193                PathPaymentStrictSendResultCode::Success => {
194                    Self::Success(PathPaymentStrictSendResultSuccess::read_xdr(r)?)
195                }
196                PathPaymentStrictSendResultCode::Malformed => Self::Malformed,
197                PathPaymentStrictSendResultCode::Underfunded => Self::Underfunded,
198                PathPaymentStrictSendResultCode::SrcNoTrust => Self::SrcNoTrust,
199                PathPaymentStrictSendResultCode::SrcNotAuthorized => Self::SrcNotAuthorized,
200                PathPaymentStrictSendResultCode::NoDestination => Self::NoDestination,
201                PathPaymentStrictSendResultCode::NoTrust => Self::NoTrust,
202                PathPaymentStrictSendResultCode::NotAuthorized => Self::NotAuthorized,
203                PathPaymentStrictSendResultCode::LineFull => Self::LineFull,
204                PathPaymentStrictSendResultCode::NoIssuer => Self::NoIssuer(Asset::read_xdr(r)?),
205                PathPaymentStrictSendResultCode::TooFewOffers => Self::TooFewOffers,
206                PathPaymentStrictSendResultCode::OfferCrossSelf => Self::OfferCrossSelf,
207                PathPaymentStrictSendResultCode::UnderDestmin => Self::UnderDestmin,
208                #[allow(unreachable_patterns)]
209                _ => return Err(Error::Invalid),
210            };
211            Ok(v)
212        })
213    }
214}
215
216impl WriteXdr for PathPaymentStrictSendResult {
217    #[cfg(feature = "std")]
218    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
219        w.with_limited_depth(|w| {
220            self.discriminant().write_xdr(w)?;
221            #[allow(clippy::match_same_arms)]
222            match self {
223                Self::Success(v) => v.write_xdr(w)?,
224                Self::Malformed => ().write_xdr(w)?,
225                Self::Underfunded => ().write_xdr(w)?,
226                Self::SrcNoTrust => ().write_xdr(w)?,
227                Self::SrcNotAuthorized => ().write_xdr(w)?,
228                Self::NoDestination => ().write_xdr(w)?,
229                Self::NoTrust => ().write_xdr(w)?,
230                Self::NotAuthorized => ().write_xdr(w)?,
231                Self::LineFull => ().write_xdr(w)?,
232                Self::NoIssuer(v) => v.write_xdr(w)?,
233                Self::TooFewOffers => ().write_xdr(w)?,
234                Self::OfferCrossSelf => ().write_xdr(w)?,
235                Self::UnderDestmin => ().write_xdr(w)?,
236            };
237            Ok(())
238        })
239    }
240}