Skip to main content

stellar_xdr/generated/
account_flags.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// AccountFlags is an XDR Enum defined as:
5///
6/// ```text
7/// enum AccountFlags
8/// { // masks for each flag
9///
10///     // Flags set on issuer accounts
11///     // TrustLines are created with authorized set to "false" requiring
12///     // the issuer to set it for each TrustLine
13///     AUTH_REQUIRED_FLAG = 0x1,
14///     // If set, the authorized flag in TrustLines can be cleared
15///     // otherwise, authorization cannot be revoked
16///     AUTH_REVOCABLE_FLAG = 0x2,
17///     // Once set, causes all AUTH_* flags to be read-only
18///     AUTH_IMMUTABLE_FLAG = 0x4,
19///     // Trustlines are created with clawback enabled set to "true",
20///     // and claimable balances created from those trustlines are created
21///     // with clawback enabled set to "true"
22///     AUTH_CLAWBACK_ENABLED_FLAG = 0x8
23/// };
24/// ```
25///
26// enum
27#[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}