Skip to main content

stellar_xdr/generated/
offer_entry_flags.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// OfferEntryFlags is an XDR Enum defined as:
5///
6/// ```text
7/// enum OfferEntryFlags
8/// {
9///     // an offer with this flag will not act on and take a reverse offer of equal
10///     // price
11///     PASSIVE_FLAG = 1
12/// };
13/// ```
14///
15// enum
16#[cfg_attr(feature = "alloc", derive(Default))]
17#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
18#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
19#[cfg_attr(
20    all(feature = "serde", feature = "alloc"),
21    derive(serde::Serialize, serde::Deserialize),
22    serde(rename_all = "snake_case")
23)]
24#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
25#[repr(i32)]
26pub enum OfferEntryFlags {
27    #[cfg_attr(feature = "alloc", default)]
28    PassiveFlag = 1,
29}
30
31impl OfferEntryFlags {
32    const _VARIANTS: &[OfferEntryFlags] = &[OfferEntryFlags::PassiveFlag];
33    pub const VARIANTS: [OfferEntryFlags; Self::_VARIANTS.len()] = {
34        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
35        let mut i = 1;
36        while i < Self::_VARIANTS.len() {
37            arr[i] = Self::_VARIANTS[i];
38            i += 1;
39        }
40        arr
41    };
42    const _VARIANTS_STR: &[&str] = &["PassiveFlag"];
43    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
44        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
45        let mut i = 1;
46        while i < Self::_VARIANTS_STR.len() {
47            arr[i] = Self::_VARIANTS_STR[i];
48            i += 1;
49        }
50        arr
51    };
52
53    #[must_use]
54    pub const fn name(&self) -> &'static str {
55        match self {
56            Self::PassiveFlag => "PassiveFlag",
57        }
58    }
59
60    #[must_use]
61    pub const fn variants() -> [OfferEntryFlags; Self::_VARIANTS.len()] {
62        Self::VARIANTS
63    }
64}
65
66impl Name for OfferEntryFlags {
67    #[must_use]
68    fn name(&self) -> &'static str {
69        Self::name(self)
70    }
71}
72
73impl Variants<OfferEntryFlags> for OfferEntryFlags {
74    fn variants() -> slice::Iter<'static, OfferEntryFlags> {
75        Self::VARIANTS.iter()
76    }
77}
78
79impl Enum for OfferEntryFlags {}
80
81impl fmt::Display for OfferEntryFlags {
82    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83        f.write_str(self.name())
84    }
85}
86
87impl TryFrom<i32> for OfferEntryFlags {
88    type Error = Error;
89
90    fn try_from(i: i32) -> Result<Self, Error> {
91        let e = match i {
92            1 => OfferEntryFlags::PassiveFlag,
93            #[allow(unreachable_patterns)]
94            _ => return Err(Error::Invalid),
95        };
96        Ok(e)
97    }
98}
99
100impl From<OfferEntryFlags> for i32 {
101    #[must_use]
102    fn from(e: OfferEntryFlags) -> Self {
103        e as Self
104    }
105}
106
107impl ReadXdr for OfferEntryFlags {
108    #[cfg(feature = "std")]
109    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
110        r.with_limited_depth(|r| {
111            let e = i32::read_xdr(r)?;
112            let v: Self = e.try_into()?;
113            Ok(v)
114        })
115    }
116}
117
118impl WriteXdr for OfferEntryFlags {
119    #[cfg(feature = "std")]
120    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
121        w.with_limited_depth(|w| {
122            let i: i32 = (*self).into();
123            i.write_xdr(w)
124        })
125    }
126}