Skip to main content

stellar_xdr/generated/
set_options_result.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// SetOptionsResult is an XDR Union defined as:
5///
6/// ```text
7/// union SetOptionsResult switch (SetOptionsResultCode code)
8/// {
9/// case SET_OPTIONS_SUCCESS:
10///     void;
11/// case SET_OPTIONS_LOW_RESERVE:
12/// case SET_OPTIONS_TOO_MANY_SIGNERS:
13/// case SET_OPTIONS_BAD_FLAGS:
14/// case SET_OPTIONS_INVALID_INFLATION:
15/// case SET_OPTIONS_CANT_CHANGE:
16/// case SET_OPTIONS_UNKNOWN_FLAG:
17/// case SET_OPTIONS_THRESHOLD_OUT_OF_RANGE:
18/// case SET_OPTIONS_BAD_SIGNER:
19/// case SET_OPTIONS_INVALID_HOME_DOMAIN:
20/// case SET_OPTIONS_AUTH_REVOCABLE_REQUIRED:
21///     void;
22/// };
23/// ```
24///
25// union with discriminant SetOptionsResultCode
26#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
27#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
28#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
29#[cfg_attr(
30    all(feature = "serde", feature = "alloc"),
31    serde_with::serde_as,
32    derive(serde::Serialize, serde::Deserialize),
33    serde(rename_all = "snake_case")
34)]
35#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
36#[allow(clippy::large_enum_variant)]
37pub enum SetOptionsResult {
38    Success,
39    LowReserve,
40    TooManySigners,
41    BadFlags,
42    InvalidInflation,
43    CantChange,
44    UnknownFlag,
45    ThresholdOutOfRange,
46    BadSigner,
47    InvalidHomeDomain,
48    AuthRevocableRequired,
49}
50
51#[cfg(feature = "alloc")]
52impl Default for SetOptionsResult {
53    fn default() -> Self {
54        Self::Success
55    }
56}
57
58impl SetOptionsResult {
59    const _VARIANTS: &[SetOptionsResultCode] = &[
60        SetOptionsResultCode::Success,
61        SetOptionsResultCode::LowReserve,
62        SetOptionsResultCode::TooManySigners,
63        SetOptionsResultCode::BadFlags,
64        SetOptionsResultCode::InvalidInflation,
65        SetOptionsResultCode::CantChange,
66        SetOptionsResultCode::UnknownFlag,
67        SetOptionsResultCode::ThresholdOutOfRange,
68        SetOptionsResultCode::BadSigner,
69        SetOptionsResultCode::InvalidHomeDomain,
70        SetOptionsResultCode::AuthRevocableRequired,
71    ];
72    pub const VARIANTS: [SetOptionsResultCode; Self::_VARIANTS.len()] = {
73        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
74        let mut i = 1;
75        while i < Self::_VARIANTS.len() {
76            arr[i] = Self::_VARIANTS[i];
77            i += 1;
78        }
79        arr
80    };
81    const _VARIANTS_STR: &[&str] = &[
82        "Success",
83        "LowReserve",
84        "TooManySigners",
85        "BadFlags",
86        "InvalidInflation",
87        "CantChange",
88        "UnknownFlag",
89        "ThresholdOutOfRange",
90        "BadSigner",
91        "InvalidHomeDomain",
92        "AuthRevocableRequired",
93    ];
94    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
95        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
96        let mut i = 1;
97        while i < Self::_VARIANTS_STR.len() {
98            arr[i] = Self::_VARIANTS_STR[i];
99            i += 1;
100        }
101        arr
102    };
103
104    #[must_use]
105    pub const fn name(&self) -> &'static str {
106        match self {
107            Self::Success => "Success",
108            Self::LowReserve => "LowReserve",
109            Self::TooManySigners => "TooManySigners",
110            Self::BadFlags => "BadFlags",
111            Self::InvalidInflation => "InvalidInflation",
112            Self::CantChange => "CantChange",
113            Self::UnknownFlag => "UnknownFlag",
114            Self::ThresholdOutOfRange => "ThresholdOutOfRange",
115            Self::BadSigner => "BadSigner",
116            Self::InvalidHomeDomain => "InvalidHomeDomain",
117            Self::AuthRevocableRequired => "AuthRevocableRequired",
118        }
119    }
120
121    #[must_use]
122    pub const fn discriminant(&self) -> SetOptionsResultCode {
123        #[allow(clippy::match_same_arms)]
124        match self {
125            Self::Success => SetOptionsResultCode::Success,
126            Self::LowReserve => SetOptionsResultCode::LowReserve,
127            Self::TooManySigners => SetOptionsResultCode::TooManySigners,
128            Self::BadFlags => SetOptionsResultCode::BadFlags,
129            Self::InvalidInflation => SetOptionsResultCode::InvalidInflation,
130            Self::CantChange => SetOptionsResultCode::CantChange,
131            Self::UnknownFlag => SetOptionsResultCode::UnknownFlag,
132            Self::ThresholdOutOfRange => SetOptionsResultCode::ThresholdOutOfRange,
133            Self::BadSigner => SetOptionsResultCode::BadSigner,
134            Self::InvalidHomeDomain => SetOptionsResultCode::InvalidHomeDomain,
135            Self::AuthRevocableRequired => SetOptionsResultCode::AuthRevocableRequired,
136        }
137    }
138
139    #[must_use]
140    pub const fn variants() -> [SetOptionsResultCode; Self::_VARIANTS.len()] {
141        Self::VARIANTS
142    }
143}
144
145impl Name for SetOptionsResult {
146    #[must_use]
147    fn name(&self) -> &'static str {
148        Self::name(self)
149    }
150}
151
152impl Discriminant<SetOptionsResultCode> for SetOptionsResult {
153    #[must_use]
154    fn discriminant(&self) -> SetOptionsResultCode {
155        Self::discriminant(self)
156    }
157}
158
159impl Variants<SetOptionsResultCode> for SetOptionsResult {
160    fn variants() -> slice::Iter<'static, SetOptionsResultCode> {
161        Self::VARIANTS.iter()
162    }
163}
164
165impl Union<SetOptionsResultCode> for SetOptionsResult {}
166
167impl ReadXdr for SetOptionsResult {
168    #[cfg(feature = "std")]
169    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
170        r.with_limited_depth(|r| {
171            let dv: SetOptionsResultCode = <SetOptionsResultCode as ReadXdr>::read_xdr(r)?;
172            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
173            let v = match dv {
174                SetOptionsResultCode::Success => Self::Success,
175                SetOptionsResultCode::LowReserve => Self::LowReserve,
176                SetOptionsResultCode::TooManySigners => Self::TooManySigners,
177                SetOptionsResultCode::BadFlags => Self::BadFlags,
178                SetOptionsResultCode::InvalidInflation => Self::InvalidInflation,
179                SetOptionsResultCode::CantChange => Self::CantChange,
180                SetOptionsResultCode::UnknownFlag => Self::UnknownFlag,
181                SetOptionsResultCode::ThresholdOutOfRange => Self::ThresholdOutOfRange,
182                SetOptionsResultCode::BadSigner => Self::BadSigner,
183                SetOptionsResultCode::InvalidHomeDomain => Self::InvalidHomeDomain,
184                SetOptionsResultCode::AuthRevocableRequired => Self::AuthRevocableRequired,
185                #[allow(unreachable_patterns)]
186                _ => return Err(Error::Invalid),
187            };
188            Ok(v)
189        })
190    }
191}
192
193impl WriteXdr for SetOptionsResult {
194    #[cfg(feature = "std")]
195    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
196        w.with_limited_depth(|w| {
197            self.discriminant().write_xdr(w)?;
198            #[allow(clippy::match_same_arms)]
199            match self {
200                Self::Success => ().write_xdr(w)?,
201                Self::LowReserve => ().write_xdr(w)?,
202                Self::TooManySigners => ().write_xdr(w)?,
203                Self::BadFlags => ().write_xdr(w)?,
204                Self::InvalidInflation => ().write_xdr(w)?,
205                Self::CantChange => ().write_xdr(w)?,
206                Self::UnknownFlag => ().write_xdr(w)?,
207                Self::ThresholdOutOfRange => ().write_xdr(w)?,
208                Self::BadSigner => ().write_xdr(w)?,
209                Self::InvalidHomeDomain => ().write_xdr(w)?,
210                Self::AuthRevocableRequired => ().write_xdr(w)?,
211            };
212            Ok(())
213        })
214    }
215}