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