Skip to main content

stellar_xdr/generated/
manage_buy_offer_result_code.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ManageBuyOfferResultCode is an XDR Enum defined as:
5///
6/// ```text
7/// enum ManageBuyOfferResultCode
8/// {
9///     // codes considered as "success" for the operation
10///     MANAGE_BUY_OFFER_SUCCESS = 0,
11///
12///     // codes considered as "failure" for the operation
13///     MANAGE_BUY_OFFER_MALFORMED = -1,     // generated offer would be invalid
14///     MANAGE_BUY_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling
15///     MANAGE_BUY_OFFER_BUY_NO_TRUST = -3,  // no trust line for what we're buying
16///     MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell
17///     MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED = -5,  // not authorized to buy
18///     MANAGE_BUY_OFFER_LINE_FULL = -6,   // can't receive more of what it's buying
19///     MANAGE_BUY_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell
20///     MANAGE_BUY_OFFER_CROSS_SELF = -8, // would cross an offer from the same user
21///     MANAGE_BUY_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling
22///     MANAGE_BUY_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying
23///
24///     // update errors
25///     MANAGE_BUY_OFFER_NOT_FOUND =
26///         -11, // offerID does not match an existing offer
27///
28///     MANAGE_BUY_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer
29/// };
30/// ```
31///
32// enum
33#[cfg_attr(feature = "alloc", derive(Default))]
34#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
35#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
36#[cfg_attr(
37    all(feature = "serde", feature = "alloc"),
38    derive(serde::Serialize, serde::Deserialize),
39    serde(rename_all = "snake_case")
40)]
41#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
42#[repr(i32)]
43pub enum ManageBuyOfferResultCode {
44    #[cfg_attr(feature = "alloc", default)]
45    Success = 0,
46    Malformed = -1,
47    SellNoTrust = -2,
48    BuyNoTrust = -3,
49    SellNotAuthorized = -4,
50    BuyNotAuthorized = -5,
51    LineFull = -6,
52    Underfunded = -7,
53    CrossSelf = -8,
54    SellNoIssuer = -9,
55    BuyNoIssuer = -10,
56    NotFound = -11,
57    LowReserve = -12,
58}
59
60impl ManageBuyOfferResultCode {
61    const _VARIANTS: &[ManageBuyOfferResultCode] = &[
62        ManageBuyOfferResultCode::Success,
63        ManageBuyOfferResultCode::Malformed,
64        ManageBuyOfferResultCode::SellNoTrust,
65        ManageBuyOfferResultCode::BuyNoTrust,
66        ManageBuyOfferResultCode::SellNotAuthorized,
67        ManageBuyOfferResultCode::BuyNotAuthorized,
68        ManageBuyOfferResultCode::LineFull,
69        ManageBuyOfferResultCode::Underfunded,
70        ManageBuyOfferResultCode::CrossSelf,
71        ManageBuyOfferResultCode::SellNoIssuer,
72        ManageBuyOfferResultCode::BuyNoIssuer,
73        ManageBuyOfferResultCode::NotFound,
74        ManageBuyOfferResultCode::LowReserve,
75    ];
76    pub const VARIANTS: [ManageBuyOfferResultCode; Self::_VARIANTS.len()] = {
77        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
78        let mut i = 1;
79        while i < Self::_VARIANTS.len() {
80            arr[i] = Self::_VARIANTS[i];
81            i += 1;
82        }
83        arr
84    };
85    const _VARIANTS_STR: &[&str] = &[
86        "Success",
87        "Malformed",
88        "SellNoTrust",
89        "BuyNoTrust",
90        "SellNotAuthorized",
91        "BuyNotAuthorized",
92        "LineFull",
93        "Underfunded",
94        "CrossSelf",
95        "SellNoIssuer",
96        "BuyNoIssuer",
97        "NotFound",
98        "LowReserve",
99    ];
100    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
101        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
102        let mut i = 1;
103        while i < Self::_VARIANTS_STR.len() {
104            arr[i] = Self::_VARIANTS_STR[i];
105            i += 1;
106        }
107        arr
108    };
109
110    #[must_use]
111    pub const fn name(&self) -> &'static str {
112        match self {
113            Self::Success => "Success",
114            Self::Malformed => "Malformed",
115            Self::SellNoTrust => "SellNoTrust",
116            Self::BuyNoTrust => "BuyNoTrust",
117            Self::SellNotAuthorized => "SellNotAuthorized",
118            Self::BuyNotAuthorized => "BuyNotAuthorized",
119            Self::LineFull => "LineFull",
120            Self::Underfunded => "Underfunded",
121            Self::CrossSelf => "CrossSelf",
122            Self::SellNoIssuer => "SellNoIssuer",
123            Self::BuyNoIssuer => "BuyNoIssuer",
124            Self::NotFound => "NotFound",
125            Self::LowReserve => "LowReserve",
126        }
127    }
128
129    #[must_use]
130    pub const fn variants() -> [ManageBuyOfferResultCode; Self::_VARIANTS.len()] {
131        Self::VARIANTS
132    }
133}
134
135impl Name for ManageBuyOfferResultCode {
136    #[must_use]
137    fn name(&self) -> &'static str {
138        Self::name(self)
139    }
140}
141
142impl Variants<ManageBuyOfferResultCode> for ManageBuyOfferResultCode {
143    fn variants() -> slice::Iter<'static, ManageBuyOfferResultCode> {
144        Self::VARIANTS.iter()
145    }
146}
147
148impl Enum for ManageBuyOfferResultCode {}
149
150impl fmt::Display for ManageBuyOfferResultCode {
151    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152        f.write_str(self.name())
153    }
154}
155
156impl TryFrom<i32> for ManageBuyOfferResultCode {
157    type Error = Error;
158
159    fn try_from(i: i32) -> Result<Self, Error> {
160        let e = match i {
161            0 => ManageBuyOfferResultCode::Success,
162            -1 => ManageBuyOfferResultCode::Malformed,
163            -2 => ManageBuyOfferResultCode::SellNoTrust,
164            -3 => ManageBuyOfferResultCode::BuyNoTrust,
165            -4 => ManageBuyOfferResultCode::SellNotAuthorized,
166            -5 => ManageBuyOfferResultCode::BuyNotAuthorized,
167            -6 => ManageBuyOfferResultCode::LineFull,
168            -7 => ManageBuyOfferResultCode::Underfunded,
169            -8 => ManageBuyOfferResultCode::CrossSelf,
170            -9 => ManageBuyOfferResultCode::SellNoIssuer,
171            -10 => ManageBuyOfferResultCode::BuyNoIssuer,
172            -11 => ManageBuyOfferResultCode::NotFound,
173            -12 => ManageBuyOfferResultCode::LowReserve,
174            #[allow(unreachable_patterns)]
175            _ => return Err(Error::Invalid),
176        };
177        Ok(e)
178    }
179}
180
181impl From<ManageBuyOfferResultCode> for i32 {
182    #[must_use]
183    fn from(e: ManageBuyOfferResultCode) -> Self {
184        e as Self
185    }
186}
187
188impl ReadXdr for ManageBuyOfferResultCode {
189    #[cfg(feature = "std")]
190    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
191        r.with_limited_depth(|r| {
192            let e = i32::read_xdr(r)?;
193            let v: Self = e.try_into()?;
194            Ok(v)
195        })
196    }
197}
198
199impl WriteXdr for ManageBuyOfferResultCode {
200    #[cfg(feature = "std")]
201    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
202        w.with_limited_depth(|w| {
203            let i: i32 = (*self).into();
204            i.write_xdr(w)
205        })
206    }
207}