Skip to main content

serde_shape/impls/
tuple.rs

1// Copyright 2026 FastLabs Developers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use alloc::vec;
16
17use crate::DeserializeShape;
18use crate::DeserializeShapeContext;
19use crate::SerializeShape;
20use crate::SerializeShapeContext;
21use crate::ShapeRef;
22
23macro_rules! tuple_shape {
24    ($($($name:ident),+;)+) => {
25        $(
26            impl<$($name),+> SerializeShape for ($($name,)+)
27            where
28                $($name: SerializeShape,)+
29            {
30                fn serialize_shape_in(context: &mut SerializeShapeContext) -> ShapeRef {
31                    ShapeRef::Tuple(vec![$($name::serialize_shape_in(context),)+])
32                }
33            }
34
35            impl<$($name),+> DeserializeShape for ($($name,)+)
36            where
37                $($name: DeserializeShape,)+
38            {
39                fn deserialize_shape_in(context: &mut DeserializeShapeContext) -> ShapeRef {
40                    ShapeRef::Tuple(vec![$($name::deserialize_shape_in(context),)+])
41                }
42            }
43        )+
44    };
45}
46
47tuple_shape! {
48    T0;
49    T0, T1;
50    T0, T1, T2;
51    T0, T1, T2, T3;
52    T0, T1, T2, T3, T4;
53    T0, T1, T2, T3, T4, T5;
54    T0, T1, T2, T3, T4, T5, T6;
55    T0, T1, T2, T3, T4, T5, T6, T7;
56    T0, T1, T2, T3, T4, T5, T6, T7, T8;
57    T0, T1, T2, T3, T4, T5, T6, T7, T8, T9;
58    T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10;
59    T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11;
60    T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12;
61    T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13;
62    T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14;
63    T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15;
64}