Skip to main content

stellar_xdr/generated/
account_id.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// AccountId is an XDR Typedef defined as:
5///
6/// ```text
7/// typedef PublicKey AccountID;
8/// ```
9///
10#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
11#[cfg_attr(feature = "alloc", derive(Default))]
12#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
13#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
14#[cfg_attr(
15    all(feature = "serde", feature = "alloc"),
16    derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr)
17)]
18#[derive(Debug)]
19pub struct AccountId(pub PublicKey);
20
21impl From<AccountId> for PublicKey {
22    #[must_use]
23    fn from(x: AccountId) -> Self {
24        x.0
25    }
26}
27
28impl From<PublicKey> for AccountId {
29    #[must_use]
30    fn from(x: PublicKey) -> Self {
31        AccountId(x)
32    }
33}
34
35impl AsRef<PublicKey> for AccountId {
36    #[must_use]
37    fn as_ref(&self) -> &PublicKey {
38        &self.0
39    }
40}
41
42impl ReadXdr for AccountId {
43    #[cfg(feature = "std")]
44    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
45        r.with_limited_depth(|r| {
46            let i = PublicKey::read_xdr(r)?;
47            let v = AccountId(i);
48            Ok(v)
49        })
50    }
51}
52
53impl WriteXdr for AccountId {
54    #[cfg(feature = "std")]
55    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
56        w.with_limited_depth(|w| self.0.write_xdr(w))
57    }
58}