stellar_xdr/generated/
asset_type.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 AssetType {
28 #[cfg_attr(feature = "alloc", default)]
29 Native = 0,
30 CreditAlphanum4 = 1,
31 CreditAlphanum12 = 2,
32 PoolShare = 3,
33}
34
35impl AssetType {
36 const _VARIANTS: &[AssetType] = &[
37 AssetType::Native,
38 AssetType::CreditAlphanum4,
39 AssetType::CreditAlphanum12,
40 AssetType::PoolShare,
41 ];
42 pub const VARIANTS: [AssetType; 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] = &["Native", "CreditAlphanum4", "CreditAlphanum12", "PoolShare"];
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::Native => "Native",
66 Self::CreditAlphanum4 => "CreditAlphanum4",
67 Self::CreditAlphanum12 => "CreditAlphanum12",
68 Self::PoolShare => "PoolShare",
69 }
70 }
71
72 #[must_use]
73 pub const fn variants() -> [AssetType; Self::_VARIANTS.len()] {
74 Self::VARIANTS
75 }
76}
77
78impl Name for AssetType {
79 #[must_use]
80 fn name(&self) -> &'static str {
81 Self::name(self)
82 }
83}
84
85impl Variants<AssetType> for AssetType {
86 fn variants() -> slice::Iter<'static, AssetType> {
87 Self::VARIANTS.iter()
88 }
89}
90
91impl Enum for AssetType {}
92
93impl fmt::Display for AssetType {
94 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95 f.write_str(self.name())
96 }
97}
98
99impl TryFrom<i32> for AssetType {
100 type Error = Error;
101
102 fn try_from(i: i32) -> Result<Self, Error> {
103 let e = match i {
104 0 => AssetType::Native,
105 1 => AssetType::CreditAlphanum4,
106 2 => AssetType::CreditAlphanum12,
107 3 => AssetType::PoolShare,
108 #[allow(unreachable_patterns)]
109 _ => return Err(Error::Invalid),
110 };
111 Ok(e)
112 }
113}
114
115impl From<AssetType> for i32 {
116 #[must_use]
117 fn from(e: AssetType) -> Self {
118 e as Self
119 }
120}
121
122impl ReadXdr for AssetType {
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 AssetType {
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}