Skip to main content

stellar_xdr/generated/
clawback_claimable_balance_result_code.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ClawbackClaimableBalanceResultCode is an XDR Enum defined as:
5///
6/// ```text
7/// enum ClawbackClaimableBalanceResultCode
8/// {
9///     // codes considered as "success" for the operation
10///     CLAWBACK_CLAIMABLE_BALANCE_SUCCESS = 0,
11///
12///     // codes considered as "failure" for the operation
13///     CLAWBACK_CLAIMABLE_BALANCE_DOES_NOT_EXIST = -1,
14///     CLAWBACK_CLAIMABLE_BALANCE_NOT_ISSUER = -2,
15///     CLAWBACK_CLAIMABLE_BALANCE_NOT_CLAWBACK_ENABLED = -3
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 ClawbackClaimableBalanceResultCode {
31    #[cfg_attr(feature = "alloc", default)]
32    Success = 0,
33    DoesNotExist = -1,
34    NotIssuer = -2,
35    NotClawbackEnabled = -3,
36}
37
38impl ClawbackClaimableBalanceResultCode {
39    const _VARIANTS: &[ClawbackClaimableBalanceResultCode] = &[
40        ClawbackClaimableBalanceResultCode::Success,
41        ClawbackClaimableBalanceResultCode::DoesNotExist,
42        ClawbackClaimableBalanceResultCode::NotIssuer,
43        ClawbackClaimableBalanceResultCode::NotClawbackEnabled,
44    ];
45    pub const VARIANTS: [ClawbackClaimableBalanceResultCode; Self::_VARIANTS.len()] = {
46        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
47        let mut i = 1;
48        while i < Self::_VARIANTS.len() {
49            arr[i] = Self::_VARIANTS[i];
50            i += 1;
51        }
52        arr
53    };
54    const _VARIANTS_STR: &[&str] = &["Success", "DoesNotExist", "NotIssuer", "NotClawbackEnabled"];
55    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
56        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
57        let mut i = 1;
58        while i < Self::_VARIANTS_STR.len() {
59            arr[i] = Self::_VARIANTS_STR[i];
60            i += 1;
61        }
62        arr
63    };
64
65    #[must_use]
66    pub const fn name(&self) -> &'static str {
67        match self {
68            Self::Success => "Success",
69            Self::DoesNotExist => "DoesNotExist",
70            Self::NotIssuer => "NotIssuer",
71            Self::NotClawbackEnabled => "NotClawbackEnabled",
72        }
73    }
74
75    #[must_use]
76    pub const fn variants() -> [ClawbackClaimableBalanceResultCode; Self::_VARIANTS.len()] {
77        Self::VARIANTS
78    }
79}
80
81impl Name for ClawbackClaimableBalanceResultCode {
82    #[must_use]
83    fn name(&self) -> &'static str {
84        Self::name(self)
85    }
86}
87
88impl Variants<ClawbackClaimableBalanceResultCode> for ClawbackClaimableBalanceResultCode {
89    fn variants() -> slice::Iter<'static, ClawbackClaimableBalanceResultCode> {
90        Self::VARIANTS.iter()
91    }
92}
93
94impl Enum for ClawbackClaimableBalanceResultCode {}
95
96impl fmt::Display for ClawbackClaimableBalanceResultCode {
97    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98        f.write_str(self.name())
99    }
100}
101
102impl TryFrom<i32> for ClawbackClaimableBalanceResultCode {
103    type Error = Error;
104
105    fn try_from(i: i32) -> Result<Self, Error> {
106        let e = match i {
107            0 => ClawbackClaimableBalanceResultCode::Success,
108            -1 => ClawbackClaimableBalanceResultCode::DoesNotExist,
109            -2 => ClawbackClaimableBalanceResultCode::NotIssuer,
110            -3 => ClawbackClaimableBalanceResultCode::NotClawbackEnabled,
111            #[allow(unreachable_patterns)]
112            _ => return Err(Error::Invalid),
113        };
114        Ok(e)
115    }
116}
117
118impl From<ClawbackClaimableBalanceResultCode> for i32 {
119    #[must_use]
120    fn from(e: ClawbackClaimableBalanceResultCode) -> Self {
121        e as Self
122    }
123}
124
125impl ReadXdr for ClawbackClaimableBalanceResultCode {
126    #[cfg(feature = "std")]
127    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
128        r.with_limited_depth(|r| {
129            let e = i32::read_xdr(r)?;
130            let v: Self = e.try_into()?;
131            Ok(v)
132        })
133    }
134}
135
136impl WriteXdr for ClawbackClaimableBalanceResultCode {
137    #[cfg(feature = "std")]
138    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
139        w.with_limited_depth(|w| {
140            let i: i32 = (*self).into();
141            i.write_xdr(w)
142        })
143    }
144}