stellar_xdr/generated/
asset_code4.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[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 AssetCode4(pub [u8; 4]);
19
20impl core::fmt::Debug for AssetCode4 {
21 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
22 let v = &self.0;
23 write!(f, "AssetCode4(")?;
24 for b in v {
25 write!(f, "{b:02x}")?;
26 }
27 write!(f, ")")?;
28 Ok(())
29 }
30}
31impl From<AssetCode4> for [u8; 4] {
32 #[must_use]
33 fn from(x: AssetCode4) -> Self {
34 x.0
35 }
36}
37
38impl From<[u8; 4]> for AssetCode4 {
39 #[must_use]
40 fn from(x: [u8; 4]) -> Self {
41 AssetCode4(x)
42 }
43}
44
45impl AsRef<[u8; 4]> for AssetCode4 {
46 #[must_use]
47 fn as_ref(&self) -> &[u8; 4] {
48 &self.0
49 }
50}
51
52impl ReadXdr for AssetCode4 {
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; 4]>::read_xdr(r)?;
57 let v = AssetCode4(i);
58 Ok(v)
59 })
60 }
61}
62
63impl WriteXdr for AssetCode4 {
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 AssetCode4 {
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 AssetCode4 {
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 AssetCode4 {
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 AssetCode4 {
94 type Error = Error;
95 fn try_from(x: &[u8]) -> Result<Self, Error> {
96 Ok(AssetCode4(x.try_into()?))
97 }
98}
99
100impl AsRef<[u8]> for AssetCode4 {
101 #[must_use]
102 fn as_ref(&self) -> &[u8] {
103 &self.0
104 }
105}