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