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