stellar_xdr/generated/
envelope_type.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "alloc", derive(Default))]
25#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
26#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
27#[cfg_attr(
28 all(feature = "serde", feature = "alloc"),
29 derive(serde::Serialize, serde::Deserialize),
30 serde(rename_all = "snake_case")
31)]
32#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
33#[repr(i32)]
34pub enum EnvelopeType {
35 #[cfg_attr(feature = "alloc", default)]
36 TxV0 = 0,
37 Scp = 1,
38 Tx = 2,
39 Auth = 3,
40 Scpvalue = 4,
41 TxFeeBump = 5,
42 OpId = 6,
43 PoolRevokeOpId = 7,
44 ContractId = 8,
45 SorobanAuthorization = 9,
46 SorobanAuthorizationWithAddress = 10,
47}
48
49impl EnvelopeType {
50 const _VARIANTS: &[EnvelopeType] = &[
51 EnvelopeType::TxV0,
52 EnvelopeType::Scp,
53 EnvelopeType::Tx,
54 EnvelopeType::Auth,
55 EnvelopeType::Scpvalue,
56 EnvelopeType::TxFeeBump,
57 EnvelopeType::OpId,
58 EnvelopeType::PoolRevokeOpId,
59 EnvelopeType::ContractId,
60 EnvelopeType::SorobanAuthorization,
61 EnvelopeType::SorobanAuthorizationWithAddress,
62 ];
63 pub const VARIANTS: [EnvelopeType; Self::_VARIANTS.len()] = {
64 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
65 let mut i = 1;
66 while i < Self::_VARIANTS.len() {
67 arr[i] = Self::_VARIANTS[i];
68 i += 1;
69 }
70 arr
71 };
72 const _VARIANTS_STR: &[&str] = &[
73 "TxV0",
74 "Scp",
75 "Tx",
76 "Auth",
77 "Scpvalue",
78 "TxFeeBump",
79 "OpId",
80 "PoolRevokeOpId",
81 "ContractId",
82 "SorobanAuthorization",
83 "SorobanAuthorizationWithAddress",
84 ];
85 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
86 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
87 let mut i = 1;
88 while i < Self::_VARIANTS_STR.len() {
89 arr[i] = Self::_VARIANTS_STR[i];
90 i += 1;
91 }
92 arr
93 };
94
95 #[must_use]
96 pub const fn name(&self) -> &'static str {
97 match self {
98 Self::TxV0 => "TxV0",
99 Self::Scp => "Scp",
100 Self::Tx => "Tx",
101 Self::Auth => "Auth",
102 Self::Scpvalue => "Scpvalue",
103 Self::TxFeeBump => "TxFeeBump",
104 Self::OpId => "OpId",
105 Self::PoolRevokeOpId => "PoolRevokeOpId",
106 Self::ContractId => "ContractId",
107 Self::SorobanAuthorization => "SorobanAuthorization",
108 Self::SorobanAuthorizationWithAddress => "SorobanAuthorizationWithAddress",
109 }
110 }
111
112 #[must_use]
113 pub const fn variants() -> [EnvelopeType; Self::_VARIANTS.len()] {
114 Self::VARIANTS
115 }
116}
117
118impl Name for EnvelopeType {
119 #[must_use]
120 fn name(&self) -> &'static str {
121 Self::name(self)
122 }
123}
124
125impl Variants<EnvelopeType> for EnvelopeType {
126 fn variants() -> slice::Iter<'static, EnvelopeType> {
127 Self::VARIANTS.iter()
128 }
129}
130
131impl Enum for EnvelopeType {}
132
133impl fmt::Display for EnvelopeType {
134 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
135 f.write_str(self.name())
136 }
137}
138
139impl TryFrom<i32> for EnvelopeType {
140 type Error = Error;
141
142 fn try_from(i: i32) -> Result<Self, Error> {
143 let e = match i {
144 0 => EnvelopeType::TxV0,
145 1 => EnvelopeType::Scp,
146 2 => EnvelopeType::Tx,
147 3 => EnvelopeType::Auth,
148 4 => EnvelopeType::Scpvalue,
149 5 => EnvelopeType::TxFeeBump,
150 6 => EnvelopeType::OpId,
151 7 => EnvelopeType::PoolRevokeOpId,
152 8 => EnvelopeType::ContractId,
153 9 => EnvelopeType::SorobanAuthorization,
154 10 => EnvelopeType::SorobanAuthorizationWithAddress,
155 #[allow(unreachable_patterns)]
156 _ => return Err(Error::Invalid),
157 };
158 Ok(e)
159 }
160}
161
162impl From<EnvelopeType> for i32 {
163 #[must_use]
164 fn from(e: EnvelopeType) -> Self {
165 e as Self
166 }
167}
168
169impl ReadXdr for EnvelopeType {
170 #[cfg(feature = "std")]
171 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
172 r.with_limited_depth(|r| {
173 let e = i32::read_xdr(r)?;
174 let v: Self = e.try_into()?;
175 Ok(v)
176 })
177 }
178}
179
180impl WriteXdr for EnvelopeType {
181 #[cfg(feature = "std")]
182 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
183 w.with_limited_depth(|w| {
184 let i: i32 = (*self).into();
185 i.write_xdr(w)
186 })
187 }
188}