Skip to main content

stellar_xdr/generated/
asset_code12.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// AssetCode12 is an XDR Typedef defined as:
5///
6/// ```text
7/// typedef opaque AssetCode12[12];
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)]
18pub struct AssetCode12(pub [u8; 12]);
19
20impl core::fmt::Debug for AssetCode12 {
21    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
22        let v = &self.0;
23        write!(f, "AssetCode12(")?;
24        for b in v {
25            write!(f, "{b:02x}")?;
26        }
27        write!(f, ")")?;
28        Ok(())
29    }
30}
31impl From<AssetCode12> for [u8; 12] {
32    #[must_use]
33    fn from(x: AssetCode12) -> Self {
34        x.0
35    }
36}
37
38impl From<[u8; 12]> for AssetCode12 {
39    #[must_use]
40    fn from(x: [u8; 12]) -> Self {
41        AssetCode12(x)
42    }
43}
44
45impl AsRef<[u8; 12]> for AssetCode12 {
46    #[must_use]
47    fn as_ref(&self) -> &[u8; 12] {
48        &self.0
49    }
50}
51
52impl ReadXdr for AssetCode12 {
53    #[cfg(feature = "std")]
54    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
55        r.with_limited_depth(|r| {
56            let i = <[u8; 12]>::read_xdr(r)?;
57            let v = AssetCode12(i);
58            Ok(v)
59        })
60    }
61}
62
63impl WriteXdr for AssetCode12 {
64    #[cfg(feature = "std")]
65    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
66        w.with_limited_depth(|w| self.0.write_xdr(w))
67    }
68}
69
70impl AssetCode12 {
71    #[must_use]
72    pub fn as_slice(&self) -> &[u8] {
73        &self.0
74    }
75}
76
77#[cfg(feature = "alloc")]
78impl TryFrom<Vec<u8>> for AssetCode12 {
79    type Error = Error;
80    fn try_from(x: Vec<u8>) -> Result<Self, Error> {
81        x.as_slice().try_into()
82    }
83}
84
85#[cfg(feature = "alloc")]
86impl TryFrom<&Vec<u8>> for AssetCode12 {
87    type Error = Error;
88    fn try_from(x: &Vec<u8>) -> Result<Self, Error> {
89        x.as_slice().try_into()
90    }
91}
92
93impl TryFrom<&[u8]> for AssetCode12 {
94    type Error = Error;
95    fn try_from(x: &[u8]) -> Result<Self, Error> {
96        Ok(AssetCode12(x.try_into()?))
97    }
98}
99
100impl AsRef<[u8]> for AssetCode12 {
101    #[must_use]
102    fn as_ref(&self) -> &[u8] {
103        &self.0
104    }
105}