Skip to main content

stellar_xdr/generated/
trust_line_flags.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// TrustLineFlags is an XDR Enum defined as:
5///
6/// ```text
7/// enum TrustLineFlags
8/// {
9///     // issuer has authorized account to perform transactions with its credit
10///     AUTHORIZED_FLAG = 1,
11///     // issuer has authorized account to maintain and reduce liabilities for its
12///     // credit
13///     AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG = 2,
14///     // issuer has specified that it may clawback its credit, and that claimable
15///     // balances created with its credit may also be clawed back
16///     TRUSTLINE_CLAWBACK_ENABLED_FLAG = 4
17/// };
18/// ```
19///
20// enum
21#[cfg_attr(feature = "alloc", derive(Default))]
22#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
23#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
24#[cfg_attr(
25    all(feature = "serde", feature = "alloc"),
26    derive(serde::Serialize, serde::Deserialize),
27    serde(rename_all = "snake_case")
28)]
29#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
30#[repr(i32)]
31pub enum TrustLineFlags {
32    #[cfg_attr(feature = "alloc", default)]
33    AuthorizedFlag = 1,
34    AuthorizedToMaintainLiabilitiesFlag = 2,
35    TrustlineClawbackEnabledFlag = 4,
36}
37
38impl TrustLineFlags {
39    const _VARIANTS: &[TrustLineFlags] = &[
40        TrustLineFlags::AuthorizedFlag,
41        TrustLineFlags::AuthorizedToMaintainLiabilitiesFlag,
42        TrustLineFlags::TrustlineClawbackEnabledFlag,
43    ];
44    pub const VARIANTS: [TrustLineFlags; Self::_VARIANTS.len()] = {
45        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
46        let mut i = 1;
47        while i < Self::_VARIANTS.len() {
48            arr[i] = Self::_VARIANTS[i];
49            i += 1;
50        }
51        arr
52    };
53    const _VARIANTS_STR: &[&str] = &[
54        "AuthorizedFlag",
55        "AuthorizedToMaintainLiabilitiesFlag",
56        "TrustlineClawbackEnabledFlag",
57    ];
58    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
59        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
60        let mut i = 1;
61        while i < Self::_VARIANTS_STR.len() {
62            arr[i] = Self::_VARIANTS_STR[i];
63            i += 1;
64        }
65        arr
66    };
67
68    #[must_use]
69    pub const fn name(&self) -> &'static str {
70        match self {
71            Self::AuthorizedFlag => "AuthorizedFlag",
72            Self::AuthorizedToMaintainLiabilitiesFlag => "AuthorizedToMaintainLiabilitiesFlag",
73            Self::TrustlineClawbackEnabledFlag => "TrustlineClawbackEnabledFlag",
74        }
75    }
76
77    #[must_use]
78    pub const fn variants() -> [TrustLineFlags; Self::_VARIANTS.len()] {
79        Self::VARIANTS
80    }
81}
82
83impl Name for TrustLineFlags {
84    #[must_use]
85    fn name(&self) -> &'static str {
86        Self::name(self)
87    }
88}
89
90impl Variants<TrustLineFlags> for TrustLineFlags {
91    fn variants() -> slice::Iter<'static, TrustLineFlags> {
92        Self::VARIANTS.iter()
93    }
94}
95
96impl Enum for TrustLineFlags {}
97
98impl fmt::Display for TrustLineFlags {
99    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100        f.write_str(self.name())
101    }
102}
103
104impl TryFrom<i32> for TrustLineFlags {
105    type Error = Error;
106
107    fn try_from(i: i32) -> Result<Self, Error> {
108        let e = match i {
109            1 => TrustLineFlags::AuthorizedFlag,
110            2 => TrustLineFlags::AuthorizedToMaintainLiabilitiesFlag,
111            4 => TrustLineFlags::TrustlineClawbackEnabledFlag,
112            #[allow(unreachable_patterns)]
113            _ => return Err(Error::Invalid),
114        };
115        Ok(e)
116    }
117}
118
119impl From<TrustLineFlags> for i32 {
120    #[must_use]
121    fn from(e: TrustLineFlags) -> Self {
122        e as Self
123    }
124}
125
126impl ReadXdr for TrustLineFlags {
127    #[cfg(feature = "std")]
128    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
129        r.with_limited_depth(|r| {
130            let e = i32::read_xdr(r)?;
131            let v: Self = e.try_into()?;
132            Ok(v)
133        })
134    }
135}
136
137impl WriteXdr for TrustLineFlags {
138    #[cfg(feature = "std")]
139    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
140        w.with_limited_depth(|w| {
141            let i: i32 = (*self).into();
142            i.write_xdr(w)
143        })
144    }
145}