Skip to main content

stellar_xdr/generated/
claim_claimable_balance_result_code.rs

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