Skip to main content

stellar_xdr/generated/
payment_result.rs

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