ink_primitives/sol/
macros.rs

1// Copyright (C) ink! contributors.
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
15/// Calls a macro upto 12 times with an increasing number of identifiers for each call.
16///
17/// # Note
18///
19/// The callee is typical a macro that implements a trait for tuples.
20///
21/// We follow the Rust standard library's convention of implementing traits for tuples up
22/// to twelve items long.
23///
24/// Ref: <https://doc.rust-lang.org/std/primitive.tuple.html#trait-implementations>
25macro_rules! impl_all_tuples {
26    // Call direct to omit unit `()`.
27    (@nonempty $macro: path) => {
28        $macro!(T1);
29        $macro!(T1, T2);
30        $macro!(T1,T2,T3);
31        $macro!(T1,T2,T3,T4);
32        $macro!(T1,T2,T3,T4,T5);
33        $macro!(T1,T2,T3,T4,T5,T6);
34        $macro!(T1,T2,T3,T4,T5,T6,T7);
35        $macro!(T1,T2,T3,T4,T5,T6,T7,T8);
36        $macro!(T1,T2,T3,T4,T5,T6,T7,T8,T9);
37        $macro!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10);
38        $macro!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11);
39        $macro!(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12);
40    };
41    // Default, include `()`.
42    ($macro: path) => {
43        $macro!();
44        impl_all_tuples!(@nonempty $macro);
45    };
46}