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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/// Takes multiple enums that wrap child enums (that can be constructed like
/// `A::BVariant(B::CVariant(C))`) and implements `From` for all types
/// involved so that the lowest type can be converted into a higher type.
///
/// The interface declares a series of mappings, from one class to the next. For
/// example, this:
/// ```
/// use treeerror::from;
///
/// struct D;
///
/// enum C {
/// DVariant(D),
/// }
/// from!(C = DVariant(D));
///
///
/// enum B {
/// CVariant(C),
/// }
/// from!(B = CVariant(C));
/// from!(B = D > C);
///
/// enum A {
/// BVariant(B),
/// }
/// from!(A = BVariant(B));
/// from!(A = C > B);
/// from!(A = D > C);
///
/// let c: C = D.into();
/// let b: B = D.into();
/// let b: B = C::from(D).into();
/// let a: A = D.into();
/// let a: A = C::from(D).into();
/// let a: A = B::from(D).into();
/// ```
///
/// is equivalent to:
/// ```
/// use treeerror::from_chain;
///
/// struct D;
///
/// enum C {
/// DVariant(D),
/// }
///
/// enum B {
/// CVariant(C),
/// }
///
/// enum A {
/// BVariant(B),
/// }
///
/// from_chain!(A : BVariant, B : CVariant, C : DVariant, D);
///
/// let c: C = D.into();
/// let b: B = D.into();
/// let b: B = C::from(D).into();
/// let a: A = D.into();
/// let a: A = C::from(D).into();
/// let a: A = B::from(D).into();
/// ```
/// Implements `From` multiple times.
///
/// You likely want to use `from_chain!` instead of `from_many!` since `from_many!`
/// omits several useful `From` implementations and typically does not work alone.
///
/// This, for example, fails to compile:
/// ```compile_fail
/// use treeerror::from_many;
///
/// struct D;
///
/// enum C {
/// DVariant(D),
/// }
///
///
/// enum B {
/// CVariant(C),
/// }
///
/// enum A {
/// BVariant(B),
/// }
///
/// from_many!(A : BVariant, B, C, D);
/// ```
///
/// And you need something like this instead:
/// ```
/// use treeerror::from_many;
///
/// struct D;
///
/// enum C {
/// DVariant(D),
/// }
///
/// // You can also use `from!(C = DVariant(D))`
/// from_many!(C : DVariant, D);
///
/// enum B {
/// CVariant(C),
/// }
///
/// from_many!(B : CVariant, C, D);
///
/// enum A {
/// BVariant(B),
/// }
///
/// from_many!(A : BVariant, B, C, D);
///
/// // commented out tests are ones that work with `from_chain!`
/// let c: C = D.into();
/// // let b: B = D.into();
/// let b: B = C::from(D).into();
/// // let a: A = D.into();
/// // let a: A = C::from(D).into();
/// let a: A = B::from(C::from(D)).into();
/// ```
///
/// There is also a variant that does conversion via an intermediate type. Syntax:
/// ```
/// use treeerror::{from_many, from};
///
/// struct D;
///
/// enum C {
/// DVariant(D),
/// }
///
/// // You can also use `from!(C = DVariant(D))`
/// from_many!(C : DVariant, D);
///
/// enum B {
/// CVariant(C),
/// }
///
/// from_many!(B : CVariant, C, D);
///
/// struct A(B);
///
/// from!(A = |b: B| A(b));
/// from_many!(A = D, C > B);
/// ```