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