stellar_xdr/generated/
claim_atom.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 ClaimAtom {
31 V0(ClaimOfferAtomV0),
32 OrderBook(ClaimOfferAtom),
33 LiquidityPool(ClaimLiquidityAtom),
34}
35
36#[cfg(feature = "alloc")]
37impl Default for ClaimAtom {
38 fn default() -> Self {
39 Self::V0(ClaimOfferAtomV0::default())
40 }
41}
42
43impl ClaimAtom {
44 const _VARIANTS: &[ClaimAtomType] = &[
45 ClaimAtomType::V0,
46 ClaimAtomType::OrderBook,
47 ClaimAtomType::LiquidityPool,
48 ];
49 pub const VARIANTS: [ClaimAtomType; 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] = &["V0", "OrderBook", "LiquidityPool"];
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::V0(_) => "V0",
73 Self::OrderBook(_) => "OrderBook",
74 Self::LiquidityPool(_) => "LiquidityPool",
75 }
76 }
77
78 #[must_use]
79 pub const fn discriminant(&self) -> ClaimAtomType {
80 #[allow(clippy::match_same_arms)]
81 match self {
82 Self::V0(_) => ClaimAtomType::V0,
83 Self::OrderBook(_) => ClaimAtomType::OrderBook,
84 Self::LiquidityPool(_) => ClaimAtomType::LiquidityPool,
85 }
86 }
87
88 #[must_use]
89 pub const fn variants() -> [ClaimAtomType; Self::_VARIANTS.len()] {
90 Self::VARIANTS
91 }
92}
93
94impl Name for ClaimAtom {
95 #[must_use]
96 fn name(&self) -> &'static str {
97 Self::name(self)
98 }
99}
100
101impl Discriminant<ClaimAtomType> for ClaimAtom {
102 #[must_use]
103 fn discriminant(&self) -> ClaimAtomType {
104 Self::discriminant(self)
105 }
106}
107
108impl Variants<ClaimAtomType> for ClaimAtom {
109 fn variants() -> slice::Iter<'static, ClaimAtomType> {
110 Self::VARIANTS.iter()
111 }
112}
113
114impl Union<ClaimAtomType> for ClaimAtom {}
115
116impl ReadXdr for ClaimAtom {
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: ClaimAtomType = <ClaimAtomType as ReadXdr>::read_xdr(r)?;
121 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
122 let v = match dv {
123 ClaimAtomType::V0 => Self::V0(ClaimOfferAtomV0::read_xdr(r)?),
124 ClaimAtomType::OrderBook => Self::OrderBook(ClaimOfferAtom::read_xdr(r)?),
125 ClaimAtomType::LiquidityPool => {
126 Self::LiquidityPool(ClaimLiquidityAtom::read_xdr(r)?)
127 }
128 #[allow(unreachable_patterns)]
129 _ => return Err(Error::Invalid),
130 };
131 Ok(v)
132 })
133 }
134}
135
136impl WriteXdr for ClaimAtom {
137 #[cfg(feature = "std")]
138 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
139 w.with_limited_depth(|w| {
140 self.discriminant().write_xdr(w)?;
141 #[allow(clippy::match_same_arms)]
142 match self {
143 Self::V0(v) => v.write_xdr(w)?,
144 Self::OrderBook(v) => v.write_xdr(w)?,
145 Self::LiquidityPool(v) => v.write_xdr(w)?,
146 };
147 Ok(())
148 })
149 }
150}