stellar_xdr/generated/
sc_spec_entry_kind.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "alloc", derive(Default))]
20#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
21#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
22#[cfg_attr(
23 all(feature = "serde", feature = "alloc"),
24 derive(serde::Serialize, serde::Deserialize),
25 serde(rename_all = "snake_case")
26)]
27#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
28#[repr(i32)]
29pub enum ScSpecEntryKind {
30 #[cfg_attr(feature = "alloc", default)]
31 FunctionV0 = 0,
32 UdtStructV0 = 1,
33 UdtUnionV0 = 2,
34 UdtEnumV0 = 3,
35 UdtErrorEnumV0 = 4,
36 EventV0 = 5,
37}
38
39impl ScSpecEntryKind {
40 const _VARIANTS: &[ScSpecEntryKind] = &[
41 ScSpecEntryKind::FunctionV0,
42 ScSpecEntryKind::UdtStructV0,
43 ScSpecEntryKind::UdtUnionV0,
44 ScSpecEntryKind::UdtEnumV0,
45 ScSpecEntryKind::UdtErrorEnumV0,
46 ScSpecEntryKind::EventV0,
47 ];
48 pub const VARIANTS: [ScSpecEntryKind; Self::_VARIANTS.len()] = {
49 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
50 let mut i = 1;
51 while i < Self::_VARIANTS.len() {
52 arr[i] = Self::_VARIANTS[i];
53 i += 1;
54 }
55 arr
56 };
57 const _VARIANTS_STR: &[&str] = &[
58 "FunctionV0",
59 "UdtStructV0",
60 "UdtUnionV0",
61 "UdtEnumV0",
62 "UdtErrorEnumV0",
63 "EventV0",
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::FunctionV0 => "FunctionV0",
79 Self::UdtStructV0 => "UdtStructV0",
80 Self::UdtUnionV0 => "UdtUnionV0",
81 Self::UdtEnumV0 => "UdtEnumV0",
82 Self::UdtErrorEnumV0 => "UdtErrorEnumV0",
83 Self::EventV0 => "EventV0",
84 }
85 }
86
87 #[must_use]
88 pub const fn variants() -> [ScSpecEntryKind; Self::_VARIANTS.len()] {
89 Self::VARIANTS
90 }
91}
92
93impl Name for ScSpecEntryKind {
94 #[must_use]
95 fn name(&self) -> &'static str {
96 Self::name(self)
97 }
98}
99
100impl Variants<ScSpecEntryKind> for ScSpecEntryKind {
101 fn variants() -> slice::Iter<'static, ScSpecEntryKind> {
102 Self::VARIANTS.iter()
103 }
104}
105
106impl Enum for ScSpecEntryKind {}
107
108impl fmt::Display for ScSpecEntryKind {
109 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110 f.write_str(self.name())
111 }
112}
113
114impl TryFrom<i32> for ScSpecEntryKind {
115 type Error = Error;
116
117 fn try_from(i: i32) -> Result<Self, Error> {
118 let e = match i {
119 0 => ScSpecEntryKind::FunctionV0,
120 1 => ScSpecEntryKind::UdtStructV0,
121 2 => ScSpecEntryKind::UdtUnionV0,
122 3 => ScSpecEntryKind::UdtEnumV0,
123 4 => ScSpecEntryKind::UdtErrorEnumV0,
124 5 => ScSpecEntryKind::EventV0,
125 #[allow(unreachable_patterns)]
126 _ => return Err(Error::Invalid),
127 };
128 Ok(e)
129 }
130}
131
132impl From<ScSpecEntryKind> for i32 {
133 #[must_use]
134 fn from(e: ScSpecEntryKind) -> Self {
135 e as Self
136 }
137}
138
139impl ReadXdr for ScSpecEntryKind {
140 #[cfg(feature = "std")]
141 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
142 r.with_limited_depth(|r| {
143 let e = i32::read_xdr(r)?;
144 let v: Self = e.try_into()?;
145 Ok(v)
146 })
147 }
148}
149
150impl WriteXdr for ScSpecEntryKind {
151 #[cfg(feature = "std")]
152 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
153 w.with_limited_depth(|w| {
154 let i: i32 = (*self).into();
155 i.write_xdr(w)
156 })
157 }
158}