bin_proto/impls/
newtype.rs

1macro_rules! impl_newtype {
2    ($ty:ident) => {
3        impl<Ctx, Tag, T> $crate::BitDecode<Ctx, Tag> for $ty<T>
4        where
5            T: $crate::BitDecode<Ctx, Tag>,
6        {
7            fn decode<R, E>(
8                read: &mut R,
9                ctx: &mut Ctx,
10                tag: Tag,
11            ) -> $crate::Result<Self>
12            where
13                R: ::bitstream_io::BitRead,
14                E: ::bitstream_io::Endianness,
15            {
16                Ok(Self($crate::BitDecode::decode::<_, E>(read,  ctx, tag)?))
17            }
18        }
19
20        impl<Ctx, Tag, T> $crate::BitEncode<Ctx, Tag> for $ty<T>
21        where
22            T: $crate::BitEncode<Ctx, Tag>,
23        {
24            fn encode<W, E>(
25                &self,
26                write: &mut W,
27                ctx: &mut Ctx,
28                tag: Tag
29            ) -> $crate::Result<()>
30            where
31                W: ::bitstream_io::BitWrite,
32                E: ::bitstream_io::Endianness,
33            {
34                $crate::BitEncode::encode::<_, E>(&self.0, write,  ctx, tag)
35            }
36        }
37
38        test_codec!($ty<u8>; $ty(1u8) => [0x01]);
39    };
40}
41
42mod wrapping {
43    use core::num::Wrapping;
44
45    impl_newtype!(Wrapping);
46    test_roundtrip!(Wrapping<u8>);
47}
48
49mod saturating {
50    use core::num::Saturating;
51
52    impl_newtype!(Saturating);
53    // TODO: https://github.com/proptest-rs/proptest/pull/585
54}