1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#[derive(Debug, Copy, Clone)]
pub struct Aligned;
#[derive(Debug, Copy, Clone)]
pub struct Unaligned;
mod sealed {
use super::{Aligned, Unaligned};
pub trait Sealed {}
impl Sealed for Aligned {}
impl Sealed for Unaligned {}
}
use self::sealed::Sealed;
pub trait Alignment: Sealed {}
impl Alignment for Aligned {}
impl Alignment for Unaligned {}
pub type CombineAlignmentOut<Lhs, Rhs> = <Lhs as CombineAlignment<Rhs>>::Output;
pub trait CombineAlignment<Rhs: Alignment> {
type Output: Alignment;
}
impl<A: Alignment> CombineAlignment<A> for Aligned {
type Output = A;
}
impl<A: Alignment> CombineAlignment<A> for Unaligned {
type Output = Unaligned;
}
macro_rules! tuple_impls {
(small=> $ty:ty = $output:ty ) => {
impl<Carry: Alignment> CombineAlignment<Carry> for $ty {
type Output = $output;
}
};
(large=>
$( ($t0:ident,$t1:ident,$t2:ident,$t3:ident,), )*
$($trailing:ident,)*
)=>{
#[allow(non_camel_case_types)]
impl<A: Alignment, $($t0,$t1,$t2,$t3,)* $($trailing,)* CombTuples >
CombineAlignment<A>
for ($($t0,$t1,$t2,$t3,)* $($trailing,)*)
where
($($trailing,)*): CombineAlignment<A>,
$( ($t0,$t1,$t2,$t3): CombineAlignment<Aligned>, )*
(
$( CombineAlignmentOut<($t0,$t1,$t2,$t3), Aligned>, )*
):CombineAlignment<
CombineAlignmentOut<($($trailing,)*), A>,
Output = CombTuples,
>,
CombTuples: Alignment,
{
type Output = CombTuples;
}
};
}
impl_all_trait_for_tuples! {
macro = tuple_impls,
true = Aligned,
false = Unaligned,
}