@@ -152,13 +152,24 @@ tuple_upcast!(Vec: A, B, C);
152
152
tuple_upcast ! ( Vec : A , B , C , D ) ;
153
153
154
154
/// This type exists to be used in judgment functions.
155
- /// You can downcast a `Vec` or `Set` to `Cons(head, tail)`
155
+ /// You can upcast/ downcast a `Vec` or `Set` to `Cons(head, tail)`
156
156
/// where `head` will be the first item in the collection
157
157
/// and tail will be a collection with the remaining items.
158
- /// Both can also be downcast to `()` which matches an empty collection.
158
+ /// Both can also be upcast/ downcast to `()` which matches an empty collection.
159
159
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
160
160
pub struct Cons < T , C > ( pub T , pub C ) ;
161
161
162
+ impl < T > UpcastFrom < Cons < T , Set < T > > > for Set < T >
163
+ where
164
+ T : Ord + Clone ,
165
+ {
166
+ fn upcast_from ( term : Cons < T , Set < T > > ) -> Self {
167
+ let Cons ( elem, mut set) = term;
168
+ set. insert ( elem) ;
169
+ set
170
+ }
171
+ }
172
+
162
173
impl < T > DowncastTo < Cons < T , Set < T > > > for Set < T >
163
174
where
164
175
T : Ord + Clone ,
@@ -174,6 +185,17 @@ where
174
185
}
175
186
}
176
187
188
+ impl < T > UpcastFrom < Cons < T , Vec < T > > > for Vec < T >
189
+ where
190
+ T : Ord + Clone ,
191
+ {
192
+ fn upcast_from ( term : Cons < T , Vec < T > > ) -> Self {
193
+ let Cons ( elem, mut vec) = term;
194
+ vec. insert ( 0 , elem) ;
195
+ vec
196
+ }
197
+ }
198
+
177
199
impl < T > DowncastTo < Cons < T , Vec < T > > > for Vec < T >
178
200
where
179
201
T : Ord + Clone ,
0 commit comments