Skip to main content

stellar_xdr/generated/
manage_data_result_code.rs

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