Skip to main content

stellar_xdr/generated/
manage_buy_offer_result.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ManageBuyOfferResult is an XDR Union defined as:
5///
6/// ```text
7/// union ManageBuyOfferResult switch (ManageBuyOfferResultCode code)
8/// {
9/// case MANAGE_BUY_OFFER_SUCCESS:
10///     ManageOfferSuccessResult success;
11/// case MANAGE_BUY_OFFER_MALFORMED:
12/// case MANAGE_BUY_OFFER_SELL_NO_TRUST:
13/// case MANAGE_BUY_OFFER_BUY_NO_TRUST:
14/// case MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED:
15/// case MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED:
16/// case MANAGE_BUY_OFFER_LINE_FULL:
17/// case MANAGE_BUY_OFFER_UNDERFUNDED:
18/// case MANAGE_BUY_OFFER_CROSS_SELF:
19/// case MANAGE_BUY_OFFER_SELL_NO_ISSUER:
20/// case MANAGE_BUY_OFFER_BUY_NO_ISSUER:
21/// case MANAGE_BUY_OFFER_NOT_FOUND:
22/// case MANAGE_BUY_OFFER_LOW_RESERVE:
23///     void;
24/// };
25/// ```
26///
27// union with discriminant ManageBuyOfferResultCode
28#[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 ManageBuyOfferResult {
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 ManageBuyOfferResult {
57    fn default() -> Self {
58        Self::Success(ManageOfferSuccessResult::default())
59    }
60}
61
62impl ManageBuyOfferResult {
63    const _VARIANTS: &[ManageBuyOfferResultCode] = &[
64        ManageBuyOfferResultCode::Success,
65        ManageBuyOfferResultCode::Malformed,
66        ManageBuyOfferResultCode::SellNoTrust,
67        ManageBuyOfferResultCode::BuyNoTrust,
68        ManageBuyOfferResultCode::SellNotAuthorized,
69        ManageBuyOfferResultCode::BuyNotAuthorized,
70        ManageBuyOfferResultCode::LineFull,
71        ManageBuyOfferResultCode::Underfunded,
72        ManageBuyOfferResultCode::CrossSelf,
73        ManageBuyOfferResultCode::SellNoIssuer,
74        ManageBuyOfferResultCode::BuyNoIssuer,
75        ManageBuyOfferResultCode::NotFound,
76        ManageBuyOfferResultCode::LowReserve,
77    ];
78    pub const VARIANTS: [ManageBuyOfferResultCode; 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) -> ManageBuyOfferResultCode {
133        #[allow(clippy::match_same_arms)]
134        match self {
135            Self::Success(_) => ManageBuyOfferResultCode::Success,
136            Self::Malformed => ManageBuyOfferResultCode::Malformed,
137            Self::SellNoTrust => ManageBuyOfferResultCode::SellNoTrust,
138            Self::BuyNoTrust => ManageBuyOfferResultCode::BuyNoTrust,
139            Self::SellNotAuthorized => ManageBuyOfferResultCode::SellNotAuthorized,
140            Self::BuyNotAuthorized => ManageBuyOfferResultCode::BuyNotAuthorized,
141            Self::LineFull => ManageBuyOfferResultCode::LineFull,
142            Self::Underfunded => ManageBuyOfferResultCode::Underfunded,
143            Self::CrossSelf => ManageBuyOfferResultCode::CrossSelf,
144            Self::SellNoIssuer => ManageBuyOfferResultCode::SellNoIssuer,
145            Self::BuyNoIssuer => ManageBuyOfferResultCode::BuyNoIssuer,
146            Self::NotFound => ManageBuyOfferResultCode::NotFound,
147            Self::LowReserve => ManageBuyOfferResultCode::LowReserve,
148        }
149    }
150
151    #[must_use]
152    pub const fn variants() -> [ManageBuyOfferResultCode; Self::_VARIANTS.len()] {
153        Self::VARIANTS
154    }
155}
156
157impl Name for ManageBuyOfferResult {
158    #[must_use]
159    fn name(&self) -> &'static str {
160        Self::name(self)
161    }
162}
163
164impl Discriminant<ManageBuyOfferResultCode> for ManageBuyOfferResult {
165    #[must_use]
166    fn discriminant(&self) -> ManageBuyOfferResultCode {
167        Self::discriminant(self)
168    }
169}
170
171impl Variants<ManageBuyOfferResultCode> for ManageBuyOfferResult {
172    fn variants() -> slice::Iter<'static, ManageBuyOfferResultCode> {
173        Self::VARIANTS.iter()
174    }
175}
176
177impl Union<ManageBuyOfferResultCode> for ManageBuyOfferResult {}
178
179impl ReadXdr for ManageBuyOfferResult {
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: ManageBuyOfferResultCode = <ManageBuyOfferResultCode as ReadXdr>::read_xdr(r)?;
184            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
185            let v = match dv {
186                ManageBuyOfferResultCode::Success => {
187                    Self::Success(ManageOfferSuccessResult::read_xdr(r)?)
188                }
189                ManageBuyOfferResultCode::Malformed => Self::Malformed,
190                ManageBuyOfferResultCode::SellNoTrust => Self::SellNoTrust,
191                ManageBuyOfferResultCode::BuyNoTrust => Self::BuyNoTrust,
192                ManageBuyOfferResultCode::SellNotAuthorized => Self::SellNotAuthorized,
193                ManageBuyOfferResultCode::BuyNotAuthorized => Self::BuyNotAuthorized,
194                ManageBuyOfferResultCode::LineFull => Self::LineFull,
195                ManageBuyOfferResultCode::Underfunded => Self::Underfunded,
196                ManageBuyOfferResultCode::CrossSelf => Self::CrossSelf,
197                ManageBuyOfferResultCode::SellNoIssuer => Self::SellNoIssuer,
198                ManageBuyOfferResultCode::BuyNoIssuer => Self::BuyNoIssuer,
199                ManageBuyOfferResultCode::NotFound => Self::NotFound,
200                ManageBuyOfferResultCode::LowReserve => Self::LowReserve,
201                #[allow(unreachable_patterns)]
202                _ => return Err(Error::Invalid),
203            };
204            Ok(v)
205        })
206    }
207}
208
209impl WriteXdr for ManageBuyOfferResult {
210    #[cfg(feature = "std")]
211    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
212        w.with_limited_depth(|w| {
213            self.discriminant().write_xdr(w)?;
214            #[allow(clippy::match_same_arms)]
215            match self {
216                Self::Success(v) => v.write_xdr(w)?,
217                Self::Malformed => ().write_xdr(w)?,
218                Self::SellNoTrust => ().write_xdr(w)?,
219                Self::BuyNoTrust => ().write_xdr(w)?,
220                Self::SellNotAuthorized => ().write_xdr(w)?,
221                Self::BuyNotAuthorized => ().write_xdr(w)?,
222                Self::LineFull => ().write_xdr(w)?,
223                Self::Underfunded => ().write_xdr(w)?,
224                Self::CrossSelf => ().write_xdr(w)?,
225                Self::SellNoIssuer => ().write_xdr(w)?,
226                Self::BuyNoIssuer => ().write_xdr(w)?,
227                Self::NotFound => ().write_xdr(w)?,
228                Self::LowReserve => ().write_xdr(w)?,
229            };
230            Ok(())
231        })
232    }
233}