Skip to main content

stellar_xdr/generated/
liquidity_pool_deposit_result_code.rs

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