1use crate::{
17 FixedI8, FixedI16, FixedI32, FixedI64, FixedI128, FixedU8, FixedU16, FixedU32, FixedU64,
18 FixedU128,
19};
20use borsh::io::{Read, Result, Write};
21use borsh::{BorshDeserialize, BorshSerialize};
22
23macro_rules! borsh_fixed {
24 ($Fixed:ident is $TBits:ident) => {
25 impl<Frac> BorshSerialize for $Fixed<Frac> {
26 #[inline]
27 fn serialize<W: Write>(&self, writer: &mut W) -> Result<()> {
28 <$TBits as BorshSerialize>::serialize(&self.bits, writer)
29 }
30 }
31
32 impl<Frac> BorshDeserialize for $Fixed<Frac> {
33 #[inline]
34 fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self> {
35 <$TBits as BorshDeserialize>::deserialize_reader(reader).map($Fixed::from_bits)
36 }
37 }
38 };
39}
40
41borsh_fixed! { FixedI8 is i8 }
42borsh_fixed! { FixedI16 is i16 }
43borsh_fixed! { FixedI32 is i32 }
44borsh_fixed! { FixedI64 is i64 }
45borsh_fixed! { FixedI128 is i128 }
46borsh_fixed! { FixedU8 is u8 }
47borsh_fixed! { FixedU16 is u16 }
48borsh_fixed! { FixedU32 is u32 }
49borsh_fixed! { FixedU64 is u64 }
50borsh_fixed! { FixedU128 is u128 }