Skip to main content

stellar_xdr/generated/
u_int256_parts.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// UInt256Parts is an XDR Struct defined as:
5///
6/// ```text
7/// struct UInt256Parts {
8///     uint64 hi_hi;
9///     uint64 hi_lo;
10///     uint64 lo_hi;
11///     uint64 lo_lo;
12/// };
13/// ```
14///
15#[cfg_attr(feature = "alloc", derive(Default))]
16#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
17#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
18#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
19#[cfg_attr(
20    all(feature = "serde", feature = "alloc"),
21    derive(serde_with::SerializeDisplay)
22)]
23pub struct UInt256Parts {
24    pub hi_hi: u64,
25    pub hi_lo: u64,
26    pub lo_hi: u64,
27    pub lo_lo: u64,
28}
29
30impl ReadXdr for UInt256Parts {
31    #[cfg(feature = "std")]
32    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
33        r.with_limited_depth(|r| {
34            Ok(Self {
35                hi_hi: u64::read_xdr(r)?,
36                hi_lo: u64::read_xdr(r)?,
37                lo_hi: u64::read_xdr(r)?,
38                lo_lo: u64::read_xdr(r)?,
39            })
40        })
41    }
42}
43
44impl WriteXdr for UInt256Parts {
45    #[cfg(feature = "std")]
46    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
47        w.with_limited_depth(|w| {
48            self.hi_hi.write_xdr(w)?;
49            self.hi_lo.write_xdr(w)?;
50            self.lo_hi.write_xdr(w)?;
51            self.lo_lo.write_xdr(w)?;
52            Ok(())
53        })
54    }
55}
56#[cfg(all(feature = "serde", feature = "alloc"))]
57impl<'de> serde::Deserialize<'de> for UInt256Parts {
58    fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
59    where
60        D: serde::Deserializer<'de>,
61    {
62        use serde::Deserialize;
63        #[derive(Deserialize)]
64        struct UInt256Parts {
65            hi_hi: u64,
66            hi_lo: u64,
67            lo_hi: u64,
68            lo_lo: u64,
69        }
70        #[derive(Deserialize)]
71        #[serde(untagged)]
72        enum UInt256PartsOrString<'a> {
73            Str(&'a str),
74            String(String),
75            UInt256Parts(UInt256Parts),
76        }
77        match UInt256PartsOrString::deserialize(deserializer)? {
78            UInt256PartsOrString::Str(s) => s.parse().map_err(serde::de::Error::custom),
79            UInt256PartsOrString::String(s) => s.parse().map_err(serde::de::Error::custom),
80            UInt256PartsOrString::UInt256Parts(UInt256Parts {
81                hi_hi,
82                hi_lo,
83                lo_hi,
84                lo_lo,
85            }) => Ok(self::UInt256Parts {
86                hi_hi,
87                hi_lo,
88                lo_hi,
89                lo_lo,
90            }),
91        }
92    }
93}