File tree 1 file changed +16
-6
lines changed
1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 21
21
// a) no ZSTs as there would be no allocation to reuse and pointer arithmetic would panic
22
22
// b) size match as required by Alloc contract
23
23
// c) alignments match as required by Alloc contract
24
- if mem:: size_of :: < T > ( ) == 0
25
- || mem:: size_of :: < T > ( )
26
- != mem:: size_of :: < <<I as SourceIter >:: Source as AsIntoIter >:: Item > ( )
27
- || mem:: align_of :: < T > ( )
28
- != mem:: align_of :: < <<I as SourceIter >:: Source as AsIntoIter >:: Item > ( )
29
- {
24
+ if <I as LayoutMatcher >:: MATCHES {
30
25
// fallback to more generic implementations
31
26
return SpecFromIterNested :: from_iter ( iterator) ;
32
27
}
@@ -154,3 +149,18 @@ where
154
149
len
155
150
}
156
151
}
152
+
153
+ trait LayoutMatcher {
154
+ type IN ;
155
+ const MATCHES : bool ;
156
+ }
157
+
158
+ impl < I , OUT > LayoutMatcher for I
159
+ where
160
+ I : Iterator < Item = OUT > + SourceIter < Source : AsIntoIter > ,
161
+ {
162
+ type IN = <<I as SourceIter >:: Source as AsIntoIter >:: Item ;
163
+ const MATCHES : bool = mem:: size_of :: < OUT > ( ) == 0
164
+ || mem:: size_of :: < OUT > ( ) != mem:: size_of :: < Self :: IN > ( )
165
+ || mem:: align_of :: < OUT > ( ) != mem:: align_of :: < Self :: IN > ( ) ;
166
+ }
You can’t perform that action at this time.
0 commit comments