Skip to main content

stellar_xdr/generated/
sc_env_meta_kind.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// ScEnvMetaKind is an XDR Enum defined as:
5///
6/// ```text
7/// enum SCEnvMetaKind
8/// {
9///     SC_ENV_META_KIND_INTERFACE_VERSION = 0
10/// };
11/// ```
12///
13// enum
14#[cfg_attr(feature = "alloc", derive(Default))]
15#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
16#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
17#[cfg_attr(
18    all(feature = "serde", feature = "alloc"),
19    derive(serde::Serialize, serde::Deserialize),
20    serde(rename_all = "snake_case")
21)]
22#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
23#[repr(i32)]
24pub enum ScEnvMetaKind {
25    #[cfg_attr(feature = "alloc", default)]
26    ScEnvMetaKindInterfaceVersion = 0,
27}
28
29impl ScEnvMetaKind {
30    const _VARIANTS: &[ScEnvMetaKind] = &[ScEnvMetaKind::ScEnvMetaKindInterfaceVersion];
31    pub const VARIANTS: [ScEnvMetaKind; Self::_VARIANTS.len()] = {
32        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
33        let mut i = 1;
34        while i < Self::_VARIANTS.len() {
35            arr[i] = Self::_VARIANTS[i];
36            i += 1;
37        }
38        arr
39    };
40    const _VARIANTS_STR: &[&str] = &["ScEnvMetaKindInterfaceVersion"];
41    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
42        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
43        let mut i = 1;
44        while i < Self::_VARIANTS_STR.len() {
45            arr[i] = Self::_VARIANTS_STR[i];
46            i += 1;
47        }
48        arr
49    };
50
51    #[must_use]
52    pub const fn name(&self) -> &'static str {
53        match self {
54            Self::ScEnvMetaKindInterfaceVersion => "ScEnvMetaKindInterfaceVersion",
55        }
56    }
57
58    #[must_use]
59    pub const fn variants() -> [ScEnvMetaKind; Self::_VARIANTS.len()] {
60        Self::VARIANTS
61    }
62}
63
64impl Name for ScEnvMetaKind {
65    #[must_use]
66    fn name(&self) -> &'static str {
67        Self::name(self)
68    }
69}
70
71impl Variants<ScEnvMetaKind> for ScEnvMetaKind {
72    fn variants() -> slice::Iter<'static, ScEnvMetaKind> {
73        Self::VARIANTS.iter()
74    }
75}
76
77impl Enum for ScEnvMetaKind {}
78
79impl fmt::Display for ScEnvMetaKind {
80    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81        f.write_str(self.name())
82    }
83}
84
85impl TryFrom<i32> for ScEnvMetaKind {
86    type Error = Error;
87
88    fn try_from(i: i32) -> Result<Self, Error> {
89        let e = match i {
90            0 => ScEnvMetaKind::ScEnvMetaKindInterfaceVersion,
91            #[allow(unreachable_patterns)]
92            _ => return Err(Error::Invalid),
93        };
94        Ok(e)
95    }
96}
97
98impl From<ScEnvMetaKind> for i32 {
99    #[must_use]
100    fn from(e: ScEnvMetaKind) -> Self {
101        e as Self
102    }
103}
104
105impl ReadXdr for ScEnvMetaKind {
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 e = i32::read_xdr(r)?;
110            let v: Self = e.try_into()?;
111            Ok(v)
112        })
113    }
114}
115
116impl WriteXdr for ScEnvMetaKind {
117    #[cfg(feature = "std")]
118    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
119        w.with_limited_depth(|w| {
120            let i: i32 = (*self).into();
121            i.write_xdr(w)
122        })
123    }
124}