Skip to main content

tlbits/as/
same.rs

1use crate::{
2    de::{BitReader, BitUnpack, BitUnpackAs},
3    ser::{BitPack, BitPackAs, BitWriter},
4};
5
6/// Adapter to convert from `*As` to regular **de**/**ser**ialization traits.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct Same;
9
10impl<T> BitPackAs<T> for Same
11where
12    T: BitPack + ?Sized,
13{
14    type Args = T::Args;
15
16    #[inline]
17    fn pack_as<W>(source: &T, writer: &mut W, args: Self::Args) -> Result<(), W::Error>
18    where
19        W: BitWriter + ?Sized,
20    {
21        T::pack(source, writer, args)
22    }
23}
24
25impl<'de, T> BitUnpackAs<'de, T> for Same
26where
27    T: BitUnpack<'de>,
28{
29    type Args = T::Args;
30
31    #[inline]
32    fn unpack_as<R>(reader: &mut R, args: Self::Args) -> Result<T, R::Error>
33    where
34        R: BitReader<'de> + ?Sized,
35    {
36        T::unpack(reader, args)
37    }
38}