rsdiff_core/ops/traits/
params.rs

1/*
2    Appellation: params <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5
6pub trait Params {
7    type Pattern;
8
9    fn into_pattern(self) -> Self::Pattern;
10}
11
12macro_rules! args_impl {
13    () => {
14        impl Params for () {
15            type Pattern = ();
16
17            fn into_pattern(self) -> Self::Pattern {
18                ()
19            }
20        }
21
22    };
23    ($n:ident) => {
24        impl<$n> Params for ($n,) {
25            type Pattern = ($n,);
26
27            fn into_pattern(self) -> Self::Pattern {
28                self
29            }
30        }
31
32        impl<$n> Params for [$n; 1] where $n: Copy {
33            type Pattern = ($n,);
34
35            fn into_pattern(self) -> Self::Pattern {
36                (self[0],)
37            }
38        }
39    };
40    ($($n:tt),*) => {
41        args_impl!(@loop $($n),*);
42    };
43    (@loop $(($($n:ident),*)),*) => {
44        $(
45            args_impl!(@loop $($n),*);
46        )*
47    };
48    (@loop $($n:ident),*) => {
49        impl<$($n),*> Params for ($($n),*) {
50            type Pattern = ($($n),*);
51
52            fn into_pattern(self) -> Self::Pattern {
53                self
54            }
55        }
56    };
57}
58
59/*
60 **************** implementations ****************
61*/
62args_impl!();
63args_impl!(A);
64args_impl!((A, B), (A, B, C), (A, B, C, D), (A, B, C, D, E));