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