1use cdbc::decode::Decode;
2use cdbc::error::BoxDynError;
3use crate::types::PgRecordDecoder;
4use crate::{PgHasArrayType, PgTypeInfo, PgValueRef, Postgres};
5use cdbc::types::Type;
6
7macro_rules! impl_type_for_tuple {
8 ($( $idx:ident : $T:ident ),*) => {
9 impl<$($T,)*> Type<Postgres> for ($($T,)*) {
10 #[inline]
11 fn type_info() -> PgTypeInfo {
12 PgTypeInfo::RECORD
13 }
14 }
15
16 impl<$($T,)*> PgHasArrayType for ($($T,)*) {
17 #[inline]
18 fn array_type_info() -> PgTypeInfo {
19 PgTypeInfo::RECORD_ARRAY
20 }
21 }
22
23 impl<'r, $($T,)*> Decode<'r, Postgres> for ($($T,)*)
24 where
25 $($T: 'r,)*
26 $($T: Type<Postgres>,)*
27 $($T: for<'a> Decode<'a, Postgres>,)*
28 {
29 fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError> {
30 #[allow(unused)]
31 let mut decoder = PgRecordDecoder::new(value)?;
32
33 $(let $idx: $T = decoder.try_decode()?;)*
34
35 Ok(($($idx,)*))
36 }
37 }
38 };
39}
40
41impl_type_for_tuple!(_1: T1);
42
43impl_type_for_tuple!(_1: T1, _2: T2);
44
45impl_type_for_tuple!(_1: T1, _2: T2, _3: T3);
46
47impl_type_for_tuple!(_1: T1, _2: T2, _3: T3, _4: T4);
48
49impl_type_for_tuple!(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5);
50
51impl_type_for_tuple!(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6);
52
53impl_type_for_tuple!(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7);
54
55impl_type_for_tuple!(
56 _1: T1,
57 _2: T2,
58 _3: T3,
59 _4: T4,
60 _5: T5,
61 _6: T6,
62 _7: T7,
63 _8: T8
64);
65
66impl_type_for_tuple!(
67 _1: T1,
68 _2: T2,
69 _3: T3,
70 _4: T4,
71 _5: T5,
72 _6: T6,
73 _7: T7,
74 _8: T8,
75 _9: T9
76);