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