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