Skip to main content

stellar_xdr/generated/
manage_data_result.rs

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