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