async_mp4/types/
tuple.rs

1use async_trait::async_trait;
2use crate::bytes_read::{Mp4Readable, ReadMp4};
3use crate::bytes_write::{Mp4Writable, WriteMp4};
4use crate::error::MP4Error;
5
6macro_rules! impl_tuple {
7    ($($t:ident),+) => {
8
9        #[async_trait]
10        impl<$($t: Mp4Readable + Send + Sync),+> Mp4Readable for ($($t,)+) {
11            async fn read<R: ReadMp4>(reader: &mut R) -> Result<Self, MP4Error> {
12                Ok((
13                    $(reader.read::<$t>().await?,)+
14                ))
15            }
16        }
17
18        #[allow(non_snake_case)]
19        impl<$($t: Mp4Writable + Send + Sync),+> Mp4Writable for ($($t,)+) {
20            fn byte_size(&self) -> usize {
21                let ($($t,)+) = self;
22                $($t.byte_size() + )+ 0
23            }
24
25            fn write<W: WriteMp4>(&self, writer: &mut W) -> Result<usize, MP4Error> {
26                let mut count = 0;
27                let ($($t,)+) = self;
28                $(count += $t.write(writer)?;)+
29                Ok(count)
30            }
31        }
32    }
33}
34
35impl_tuple!(A);
36impl_tuple!(A, B);
37impl_tuple!(A, B, C);
38impl_tuple!(A, B, C, D);
39impl_tuple!(A, B, C, D, E);
40impl_tuple!(A, B, C, D, E, F);
41impl_tuple!(A, B, C, D, E, F, G);