Skip to main content

stellar_xdr/generated/
survey_response_body.rs

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