Skip to main content

stellar_xdr/generated/
manage_sell_offer_result_code.rs

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