Skip to main content

stellar_xdr/generated/
int128_parts.rs

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