Skip to main content

stellar_xdr/generated/
revoke_sponsorship_result_code.rs

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