Skip to main content

stellar_xdr/generated/
sc_spec_event_param_location_v0.rs

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