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