stellar_xdr/generated/
stellar_value_ext.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
28#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
29#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
30#[cfg_attr(
31 all(feature = "serde", feature = "alloc"),
32 serde_with::serde_as,
33 derive(serde::Serialize, serde::Deserialize),
34 serde(rename_all = "snake_case")
35)]
36#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
37#[allow(clippy::large_enum_variant)]
38pub enum StellarValueExt {
39 Basic,
40 Signed(LedgerCloseValueSignature),
41 #[cfg(feature = "cap_0083")]
42 EmptyTxSet(StellarValueProposedValue),
43}
44
45#[cfg(feature = "alloc")]
46impl Default for StellarValueExt {
47 fn default() -> Self {
48 Self::Basic
49 }
50}
51
52impl StellarValueExt {
53 const _VARIANTS: &[StellarValueType] = &[
54 StellarValueType::Basic,
55 StellarValueType::Signed,
56 #[cfg(feature = "cap_0083")]
57 StellarValueType::EmptyTxSet,
58 ];
59 pub const VARIANTS: [StellarValueType; Self::_VARIANTS.len()] = {
60 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
61 let mut i = 1;
62 while i < Self::_VARIANTS.len() {
63 arr[i] = Self::_VARIANTS[i];
64 i += 1;
65 }
66 arr
67 };
68 const _VARIANTS_STR: &[&str] = &[
69 "Basic",
70 "Signed",
71 #[cfg(feature = "cap_0083")]
72 "EmptyTxSet",
73 ];
74 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
75 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
76 let mut i = 1;
77 while i < Self::_VARIANTS_STR.len() {
78 arr[i] = Self::_VARIANTS_STR[i];
79 i += 1;
80 }
81 arr
82 };
83
84 #[must_use]
85 pub const fn name(&self) -> &'static str {
86 match self {
87 Self::Basic => "Basic",
88 Self::Signed(_) => "Signed",
89 #[cfg(feature = "cap_0083")]
90 Self::EmptyTxSet(_) => "EmptyTxSet",
91 }
92 }
93
94 #[must_use]
95 pub const fn discriminant(&self) -> StellarValueType {
96 #[allow(clippy::match_same_arms)]
97 match self {
98 Self::Basic => StellarValueType::Basic,
99 Self::Signed(_) => StellarValueType::Signed,
100 #[cfg(feature = "cap_0083")]
101 Self::EmptyTxSet(_) => StellarValueType::EmptyTxSet,
102 }
103 }
104
105 #[must_use]
106 pub const fn variants() -> [StellarValueType; Self::_VARIANTS.len()] {
107 Self::VARIANTS
108 }
109}
110
111impl Name for StellarValueExt {
112 #[must_use]
113 fn name(&self) -> &'static str {
114 Self::name(self)
115 }
116}
117
118impl Discriminant<StellarValueType> for StellarValueExt {
119 #[must_use]
120 fn discriminant(&self) -> StellarValueType {
121 Self::discriminant(self)
122 }
123}
124
125impl Variants<StellarValueType> for StellarValueExt {
126 fn variants() -> slice::Iter<'static, StellarValueType> {
127 Self::VARIANTS.iter()
128 }
129}
130
131impl Union<StellarValueType> for StellarValueExt {}
132
133impl ReadXdr for StellarValueExt {
134 #[cfg(feature = "std")]
135 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
136 r.with_limited_depth(|r| {
137 let dv: StellarValueType = <StellarValueType as ReadXdr>::read_xdr(r)?;
138 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
139 let v = match dv {
140 StellarValueType::Basic => Self::Basic,
141 StellarValueType::Signed => Self::Signed(LedgerCloseValueSignature::read_xdr(r)?),
142 #[cfg(feature = "cap_0083")]
143 StellarValueType::EmptyTxSet => {
144 Self::EmptyTxSet(StellarValueProposedValue::read_xdr(r)?)
145 }
146 #[allow(unreachable_patterns)]
147 _ => return Err(Error::Invalid),
148 };
149 Ok(v)
150 })
151 }
152}
153
154impl WriteXdr for StellarValueExt {
155 #[cfg(feature = "std")]
156 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
157 w.with_limited_depth(|w| {
158 self.discriminant().write_xdr(w)?;
159 #[allow(clippy::match_same_arms)]
160 match self {
161 Self::Basic => ().write_xdr(w)?,
162 Self::Signed(v) => v.write_xdr(w)?,
163 #[cfg(feature = "cap_0083")]
164 Self::EmptyTxSet(v) => v.write_xdr(w)?,
165 };
166 Ok(())
167 })
168 }
169}