1use crate::{Error, Serializable};
8
9macro_rules! impl_serializable {
10 ($ty:ty) => {
11 impl Serializable<{ core::mem::size_of::<$ty>() }> for $ty {
12 type Error = Error;
13
14 fn from_bytes(buf: &[u8; Self::SIZE]) -> Result<Self, Self::Error> {
15 Ok(Self::from_le_bytes(*buf))
16 }
17
18 fn to_bytes(&self) -> [u8; Self::SIZE] {
19 <$ty>::to_le_bytes(*self)
20 }
21 }
22 };
23}
24
25impl_serializable!(u8);
26impl_serializable!(u16);
27impl_serializable!(u32);
28impl_serializable!(u64);
29impl_serializable!(u128);
30
31impl_serializable!(i8);
32impl_serializable!(i16);
33impl_serializable!(i32);
34impl_serializable!(i64);
35impl_serializable!(i128);