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
94
95
96
97
98
99
100
101
102
103
104
105
#[macro_export]
macro_rules! part {
($part:ident) => { part!(@template $part () ($crate::AbstractPart)); };
(pub $part:ident) => { part!(@template $part (pub) ($crate::AbstractPart)); };
($part:ident : $field:ty) => { part!(@template $part () ($crate::Field<$field>)); };
(pub $part:ident : $field:ty) => { part!(@template $part (pub) ($crate::Field<$field>)); };
(@template $part:ident ($($vis:tt)*) ($($part_type:tt)*)) => {
#[derive(Default)]
$($vis)* struct $part;
impl $crate::Part for $part {
type PartType = $($part_type)*;
}
impl<InnerPart: $crate::Part> ::std::ops::BitOr<InnerPart> for $part {
type Output = $crate::Nested<$part, InnerPart>;
fn bitor(self, _rhs: InnerPart) -> Self::Output {
std::default::Default::default()
}
}
}
}
#[macro_export]
macro_rules! partial {
($target:ty) => { $crate::Ref<$target> };
($target_lt:lifetime $target:ty) => { $crate::Ref<$target_lt, $target> };
($target:ty, $($parts:tt)* ) => {
partial!(@extend $crate::Ref<$target>, $($parts)*)
};
($target_lt:lifetime $target:ty, $($parts:tt)*) => {
partial!(@extend $crate::Ref<$target_lt, $target>, $($parts)*)
};
(@extend $target:ty) => {$target};
(@extend $target:ty, ) => {$target};
(@extend $target:ty, mut $($part:ty)|* , $($rest:tt)*) => {
partial!(@extend $crate::Mut<$crate::nested_part!($($part)|*), $target>, $($rest)*)
};
(@extend $target:ty, mut $($part:ty)|*) => {
partial!(@extend $target, mut $($part)|*, )
};
(@extend $target:ty, $($part:ty)|* , $($rest:tt)*) => {
partial!(@extend $crate::Const<$crate::nested_part!($($part)|*), $target>, $($rest)*)
};
(@extend $target:ty, $($part:ty)|*) => {
partial!(@extend $target, $($part)|*, )
};
}
#[macro_export]
macro_rules! nested_part {
($target:ty) => { $target };
($target:ty | $part:ty) => {
$crate::Nested<$target , $part>
};
($target:ty | $part:ty | $($subparts:ty)|*) => {
nested_part!($crate::Nested<$target , $part> | $($subparts)|*)
};
}
#[macro_export]
macro_rules! split_borrow {
($target:ident = &($($parts:tt)*) $from:ident) => {
split_borrow!($target, $from = &($($parts)*) $from)
};
($target:ident, $rest:ident = &($($parts:tt)*) $from:expr) => {
#[allow(unused_variables, unused_mut)]
let (mut $target, mut $rest) = ($from).split_borrow::<partial!(_, $($parts)*), _>();
};
}