stellar_xdr/generated/
change_trust_result.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
25#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
26#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
27#[cfg_attr(
28 all(feature = "serde", feature = "alloc"),
29 serde_with::serde_as,
30 derive(serde::Serialize, serde::Deserialize),
31 serde(rename_all = "snake_case")
32)]
33#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
34#[allow(clippy::large_enum_variant)]
35pub enum ChangeTrustResult {
36 Success,
37 Malformed,
38 NoIssuer,
39 InvalidLimit,
40 LowReserve,
41 SelfNotAllowed,
42 TrustLineMissing,
43 CannotDelete,
44 NotAuthMaintainLiabilities,
45}
46
47#[cfg(feature = "alloc")]
48impl Default for ChangeTrustResult {
49 fn default() -> Self {
50 Self::Success
51 }
52}
53
54impl ChangeTrustResult {
55 const _VARIANTS: &[ChangeTrustResultCode] = &[
56 ChangeTrustResultCode::Success,
57 ChangeTrustResultCode::Malformed,
58 ChangeTrustResultCode::NoIssuer,
59 ChangeTrustResultCode::InvalidLimit,
60 ChangeTrustResultCode::LowReserve,
61 ChangeTrustResultCode::SelfNotAllowed,
62 ChangeTrustResultCode::TrustLineMissing,
63 ChangeTrustResultCode::CannotDelete,
64 ChangeTrustResultCode::NotAuthMaintainLiabilities,
65 ];
66 pub const VARIANTS: [ChangeTrustResultCode; Self::_VARIANTS.len()] = {
67 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
68 let mut i = 1;
69 while i < Self::_VARIANTS.len() {
70 arr[i] = Self::_VARIANTS[i];
71 i += 1;
72 }
73 arr
74 };
75 const _VARIANTS_STR: &[&str] = &[
76 "Success",
77 "Malformed",
78 "NoIssuer",
79 "InvalidLimit",
80 "LowReserve",
81 "SelfNotAllowed",
82 "TrustLineMissing",
83 "CannotDelete",
84 "NotAuthMaintainLiabilities",
85 ];
86 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
87 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
88 let mut i = 1;
89 while i < Self::_VARIANTS_STR.len() {
90 arr[i] = Self::_VARIANTS_STR[i];
91 i += 1;
92 }
93 arr
94 };
95
96 #[must_use]
97 pub const fn name(&self) -> &'static str {
98 match self {
99 Self::Success => "Success",
100 Self::Malformed => "Malformed",
101 Self::NoIssuer => "NoIssuer",
102 Self::InvalidLimit => "InvalidLimit",
103 Self::LowReserve => "LowReserve",
104 Self::SelfNotAllowed => "SelfNotAllowed",
105 Self::TrustLineMissing => "TrustLineMissing",
106 Self::CannotDelete => "CannotDelete",
107 Self::NotAuthMaintainLiabilities => "NotAuthMaintainLiabilities",
108 }
109 }
110
111 #[must_use]
112 pub const fn discriminant(&self) -> ChangeTrustResultCode {
113 #[allow(clippy::match_same_arms)]
114 match self {
115 Self::Success => ChangeTrustResultCode::Success,
116 Self::Malformed => ChangeTrustResultCode::Malformed,
117 Self::NoIssuer => ChangeTrustResultCode::NoIssuer,
118 Self::InvalidLimit => ChangeTrustResultCode::InvalidLimit,
119 Self::LowReserve => ChangeTrustResultCode::LowReserve,
120 Self::SelfNotAllowed => ChangeTrustResultCode::SelfNotAllowed,
121 Self::TrustLineMissing => ChangeTrustResultCode::TrustLineMissing,
122 Self::CannotDelete => ChangeTrustResultCode::CannotDelete,
123 Self::NotAuthMaintainLiabilities => ChangeTrustResultCode::NotAuthMaintainLiabilities,
124 }
125 }
126
127 #[must_use]
128 pub const fn variants() -> [ChangeTrustResultCode; Self::_VARIANTS.len()] {
129 Self::VARIANTS
130 }
131}
132
133impl Name for ChangeTrustResult {
134 #[must_use]
135 fn name(&self) -> &'static str {
136 Self::name(self)
137 }
138}
139
140impl Discriminant<ChangeTrustResultCode> for ChangeTrustResult {
141 #[must_use]
142 fn discriminant(&self) -> ChangeTrustResultCode {
143 Self::discriminant(self)
144 }
145}
146
147impl Variants<ChangeTrustResultCode> for ChangeTrustResult {
148 fn variants() -> slice::Iter<'static, ChangeTrustResultCode> {
149 Self::VARIANTS.iter()
150 }
151}
152
153impl Union<ChangeTrustResultCode> for ChangeTrustResult {}
154
155impl ReadXdr for ChangeTrustResult {
156 #[cfg(feature = "std")]
157 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
158 r.with_limited_depth(|r| {
159 let dv: ChangeTrustResultCode = <ChangeTrustResultCode as ReadXdr>::read_xdr(r)?;
160 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
161 let v = match dv {
162 ChangeTrustResultCode::Success => Self::Success,
163 ChangeTrustResultCode::Malformed => Self::Malformed,
164 ChangeTrustResultCode::NoIssuer => Self::NoIssuer,
165 ChangeTrustResultCode::InvalidLimit => Self::InvalidLimit,
166 ChangeTrustResultCode::LowReserve => Self::LowReserve,
167 ChangeTrustResultCode::SelfNotAllowed => Self::SelfNotAllowed,
168 ChangeTrustResultCode::TrustLineMissing => Self::TrustLineMissing,
169 ChangeTrustResultCode::CannotDelete => Self::CannotDelete,
170 ChangeTrustResultCode::NotAuthMaintainLiabilities => {
171 Self::NotAuthMaintainLiabilities
172 }
173 #[allow(unreachable_patterns)]
174 _ => return Err(Error::Invalid),
175 };
176 Ok(v)
177 })
178 }
179}
180
181impl WriteXdr for ChangeTrustResult {
182 #[cfg(feature = "std")]
183 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
184 w.with_limited_depth(|w| {
185 self.discriminant().write_xdr(w)?;
186 #[allow(clippy::match_same_arms)]
187 match self {
188 Self::Success => ().write_xdr(w)?,
189 Self::Malformed => ().write_xdr(w)?,
190 Self::NoIssuer => ().write_xdr(w)?,
191 Self::InvalidLimit => ().write_xdr(w)?,
192 Self::LowReserve => ().write_xdr(w)?,
193 Self::SelfNotAllowed => ().write_xdr(w)?,
194 Self::TrustLineMissing => ().write_xdr(w)?,
195 Self::CannotDelete => ().write_xdr(w)?,
196 Self::NotAuthMaintainLiabilities => ().write_xdr(w)?,
197 };
198 Ok(())
199 })
200 }
201}