Skip to main content

stellar_xdr/generated/
sc_spec_event_data_format.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ScSpecEventDataFormat is an XDR Enum defined as:
5///
6/// ```text
7/// enum SCSpecEventDataFormat
8/// {
9///     SC_SPEC_EVENT_DATA_FORMAT_SINGLE_VALUE = 0,
10///     SC_SPEC_EVENT_DATA_FORMAT_VEC = 1,
11///     SC_SPEC_EVENT_DATA_FORMAT_MAP = 2
12/// };
13/// ```
14///
15// enum
16#[cfg_attr(feature = "alloc", derive(Default))]
17#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
18#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
19#[cfg_attr(
20    all(feature = "serde", feature = "alloc"),
21    derive(serde::Serialize, serde::Deserialize),
22    serde(rename_all = "snake_case")
23)]
24#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
25#[repr(i32)]
26pub enum ScSpecEventDataFormat {
27    #[cfg_attr(feature = "alloc", default)]
28    SingleValue = 0,
29    Vec = 1,
30    Map = 2,
31}
32
33impl ScSpecEventDataFormat {
34    const _VARIANTS: &[ScSpecEventDataFormat] = &[
35        ScSpecEventDataFormat::SingleValue,
36        ScSpecEventDataFormat::Vec,
37        ScSpecEventDataFormat::Map,
38    ];
39    pub const VARIANTS: [ScSpecEventDataFormat; Self::_VARIANTS.len()] = {
40        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
41        let mut i = 1;
42        while i < Self::_VARIANTS.len() {
43            arr[i] = Self::_VARIANTS[i];
44            i += 1;
45        }
46        arr
47    };
48    const _VARIANTS_STR: &[&str] = &["SingleValue", "Vec", "Map"];
49    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
50        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
51        let mut i = 1;
52        while i < Self::_VARIANTS_STR.len() {
53            arr[i] = Self::_VARIANTS_STR[i];
54            i += 1;
55        }
56        arr
57    };
58
59    #[must_use]
60    pub const fn name(&self) -> &'static str {
61        match self {
62            Self::SingleValue => "SingleValue",
63            Self::Vec => "Vec",
64            Self::Map => "Map",
65        }
66    }
67
68    #[must_use]
69    pub const fn variants() -> [ScSpecEventDataFormat; Self::_VARIANTS.len()] {
70        Self::VARIANTS
71    }
72}
73
74impl Name for ScSpecEventDataFormat {
75    #[must_use]
76    fn name(&self) -> &'static str {
77        Self::name(self)
78    }
79}
80
81impl Variants<ScSpecEventDataFormat> for ScSpecEventDataFormat {
82    fn variants() -> slice::Iter<'static, ScSpecEventDataFormat> {
83        Self::VARIANTS.iter()
84    }
85}
86
87impl Enum for ScSpecEventDataFormat {}
88
89impl fmt::Display for ScSpecEventDataFormat {
90    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91        f.write_str(self.name())
92    }
93}
94
95impl TryFrom<i32> for ScSpecEventDataFormat {
96    type Error = Error;
97
98    fn try_from(i: i32) -> Result<Self, Error> {
99        let e = match i {
100            0 => ScSpecEventDataFormat::SingleValue,
101            1 => ScSpecEventDataFormat::Vec,
102            2 => ScSpecEventDataFormat::Map,
103            #[allow(unreachable_patterns)]
104            _ => return Err(Error::Invalid),
105        };
106        Ok(e)
107    }
108}
109
110impl From<ScSpecEventDataFormat> for i32 {
111    #[must_use]
112    fn from(e: ScSpecEventDataFormat) -> Self {
113        e as Self
114    }
115}
116
117impl ReadXdr for ScSpecEventDataFormat {
118    #[cfg(feature = "std")]
119    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
120        r.with_limited_depth(|r| {
121            let e = i32::read_xdr(r)?;
122            let v: Self = e.try_into()?;
123            Ok(v)
124        })
125    }
126}
127
128impl WriteXdr for ScSpecEventDataFormat {
129    #[cfg(feature = "std")]
130    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
131        w.with_limited_depth(|w| {
132            let i: i32 = (*self).into();
133            i.write_xdr(w)
134        })
135    }
136}