Skip to main content

stellar_xdr/generated/
liquidity_pool_withdraw_result_code.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// LiquidityPoolWithdrawResultCode is an XDR Enum defined as:
5///
6/// ```text
7/// enum LiquidityPoolWithdrawResultCode
8/// {
9///     // codes considered as "success" for the operation
10///     LIQUIDITY_POOL_WITHDRAW_SUCCESS = 0,
11///
12///     // codes considered as "failure" for the operation
13///     LIQUIDITY_POOL_WITHDRAW_MALFORMED = -1,    // bad input
14///     LIQUIDITY_POOL_WITHDRAW_NO_TRUST = -2,     // no trust line for one of the
15///                                                // assets
16///     LIQUIDITY_POOL_WITHDRAW_UNDERFUNDED = -3,  // not enough balance of the
17///                                                // pool share
18///     LIQUIDITY_POOL_WITHDRAW_LINE_FULL = -4,    // would go above limit for one
19///                                                // of the assets
20///     LIQUIDITY_POOL_WITHDRAW_UNDER_MINIMUM = -5, // didn't withdraw enough
21///     LIQUIDITY_POOL_WITHDRAW_TRUSTLINE_FROZEN = -6  // trustline for one of the
22///                                                    // assets is frozen
23/// };
24/// ```
25///
26// enum
27#[cfg_attr(feature = "alloc", derive(Default))]
28#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
29#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
30#[cfg_attr(
31    all(feature = "serde", feature = "alloc"),
32    derive(serde::Serialize, serde::Deserialize),
33    serde(rename_all = "snake_case")
34)]
35#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
36#[repr(i32)]
37pub enum LiquidityPoolWithdrawResultCode {
38    #[cfg_attr(feature = "alloc", default)]
39    Success = 0,
40    Malformed = -1,
41    NoTrust = -2,
42    Underfunded = -3,
43    LineFull = -4,
44    UnderMinimum = -5,
45    TrustlineFrozen = -6,
46}
47
48impl LiquidityPoolWithdrawResultCode {
49    const _VARIANTS: &[LiquidityPoolWithdrawResultCode] = &[
50        LiquidityPoolWithdrawResultCode::Success,
51        LiquidityPoolWithdrawResultCode::Malformed,
52        LiquidityPoolWithdrawResultCode::NoTrust,
53        LiquidityPoolWithdrawResultCode::Underfunded,
54        LiquidityPoolWithdrawResultCode::LineFull,
55        LiquidityPoolWithdrawResultCode::UnderMinimum,
56        LiquidityPoolWithdrawResultCode::TrustlineFrozen,
57    ];
58    pub const VARIANTS: [LiquidityPoolWithdrawResultCode; Self::_VARIANTS.len()] = {
59        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
60        let mut i = 1;
61        while i < Self::_VARIANTS.len() {
62            arr[i] = Self::_VARIANTS[i];
63            i += 1;
64        }
65        arr
66    };
67    const _VARIANTS_STR: &[&str] = &[
68        "Success",
69        "Malformed",
70        "NoTrust",
71        "Underfunded",
72        "LineFull",
73        "UnderMinimum",
74        "TrustlineFrozen",
75    ];
76    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
77        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
78        let mut i = 1;
79        while i < Self::_VARIANTS_STR.len() {
80            arr[i] = Self::_VARIANTS_STR[i];
81            i += 1;
82        }
83        arr
84    };
85
86    #[must_use]
87    pub const fn name(&self) -> &'static str {
88        match self {
89            Self::Success => "Success",
90            Self::Malformed => "Malformed",
91            Self::NoTrust => "NoTrust",
92            Self::Underfunded => "Underfunded",
93            Self::LineFull => "LineFull",
94            Self::UnderMinimum => "UnderMinimum",
95            Self::TrustlineFrozen => "TrustlineFrozen",
96        }
97    }
98
99    #[must_use]
100    pub const fn variants() -> [LiquidityPoolWithdrawResultCode; Self::_VARIANTS.len()] {
101        Self::VARIANTS
102    }
103}
104
105impl Name for LiquidityPoolWithdrawResultCode {
106    #[must_use]
107    fn name(&self) -> &'static str {
108        Self::name(self)
109    }
110}
111
112impl Variants<LiquidityPoolWithdrawResultCode> for LiquidityPoolWithdrawResultCode {
113    fn variants() -> slice::Iter<'static, LiquidityPoolWithdrawResultCode> {
114        Self::VARIANTS.iter()
115    }
116}
117
118impl Enum for LiquidityPoolWithdrawResultCode {}
119
120impl fmt::Display for LiquidityPoolWithdrawResultCode {
121    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122        f.write_str(self.name())
123    }
124}
125
126impl TryFrom<i32> for LiquidityPoolWithdrawResultCode {
127    type Error = Error;
128
129    fn try_from(i: i32) -> Result<Self, Error> {
130        let e = match i {
131            0 => LiquidityPoolWithdrawResultCode::Success,
132            -1 => LiquidityPoolWithdrawResultCode::Malformed,
133            -2 => LiquidityPoolWithdrawResultCode::NoTrust,
134            -3 => LiquidityPoolWithdrawResultCode::Underfunded,
135            -4 => LiquidityPoolWithdrawResultCode::LineFull,
136            -5 => LiquidityPoolWithdrawResultCode::UnderMinimum,
137            -6 => LiquidityPoolWithdrawResultCode::TrustlineFrozen,
138            #[allow(unreachable_patterns)]
139            _ => return Err(Error::Invalid),
140        };
141        Ok(e)
142    }
143}
144
145impl From<LiquidityPoolWithdrawResultCode> for i32 {
146    #[must_use]
147    fn from(e: LiquidityPoolWithdrawResultCode) -> Self {
148        e as Self
149    }
150}
151
152impl ReadXdr for LiquidityPoolWithdrawResultCode {
153    #[cfg(feature = "std")]
154    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
155        r.with_limited_depth(|r| {
156            let e = i32::read_xdr(r)?;
157            let v: Self = e.try_into()?;
158            Ok(v)
159        })
160    }
161}
162
163impl WriteXdr for LiquidityPoolWithdrawResultCode {
164    #[cfg(feature = "std")]
165    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
166        w.with_limited_depth(|w| {
167            let i: i32 = (*self).into();
168            i.write_xdr(w)
169        })
170    }
171}