@@ -19,11 +19,12 @@ pub struct Drain<
19
19
' a ,
20
20
T : ' a ,
21
21
#[ unstable( feature = "allocator_api" , issue = "32838" ) ] A : Allocator = Global ,
22
+ const COOP_PREFERRED : bool = { alloc:: SHORT_TERM_VEC_PREFERS_COOP }
22
23
>
23
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
24
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
24
25
// We can't just use a &mut VecDeque<T, A>, as that would make Drain invariant over T
25
26
// and we want it to be covariant instead
26
- deque : NonNull < VecDeque < T , A > > ,
27
+ deque : NonNull < VecDeque < T , A , COOP_PREFERRED > > ,
27
28
// drain_start is stored in deque.len
28
29
drain_len : usize ,
29
30
// index into the logical array, not the physical one (always lies in [0..deque.len))
@@ -35,10 +36,10 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
35
36
_marker : PhantomData < & ' a T > ,
36
37
}
37
38
38
- impl < ' a , T , A : Allocator > Drain < ' a , T , A >
39
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
39
+ impl < ' a , T , A : Allocator , const COOP_PREFERRED : bool > Drain < ' a , T , A , COOP_PREFERRED >
40
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
40
41
pub ( super ) unsafe fn new (
41
- deque : & ' a mut VecDeque < T , A > ,
42
+ deque : & ' a mut VecDeque < T , A , COOP_PREFERRED > ,
42
43
drain_start : usize ,
43
44
drain_len : usize ,
44
45
) -> Self {
@@ -90,8 +91,8 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
90
91
}
91
92
92
93
#[ stable( feature = "collection_debug" , since = "1.17.0" ) ]
93
- impl < T : fmt:: Debug , A : Allocator > fmt:: Debug for Drain < ' _ , T , A >
94
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
94
+ impl < T : fmt:: Debug , A : Allocator , const COOP_PREFERRED : bool > fmt:: Debug for Drain < ' _ , T , A , COOP_PREFERRED >
95
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
95
96
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
96
97
f. debug_tuple ( "Drain" )
97
98
. field ( & self . drain_len )
@@ -103,21 +104,21 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
103
104
}
104
105
105
106
#[ stable( feature = "drain" , since = "1.6.0" ) ]
106
- unsafe impl < T : Sync , A : Allocator + Sync > Sync for Drain < ' _ , T , A >
107
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : { }
107
+ unsafe impl < T : Sync , A : Allocator + Sync , const COOP_PREFERRED : bool > Sync for Drain < ' _ , T , A , COOP_PREFERRED >
108
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : { }
108
109
#[ stable( feature = "drain" , since = "1.6.0" ) ]
109
- unsafe impl < T : Send , A : Allocator + Send > Send for Drain < ' _ , T , A >
110
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : { }
110
+ unsafe impl < T : Send , A : Allocator + Send , const COOP_PREFERRED : bool > Send for Drain < ' _ , T , A , COOP_PREFERRED >
111
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : { }
111
112
112
113
#[ stable( feature = "drain" , since = "1.6.0" ) ]
113
- impl < T , A : Allocator > Drop for Drain < ' _ , T , A >
114
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
114
+ impl < T , A : Allocator , const COOP_PREFERRED : bool > Drop for Drain < ' _ , T , A , COOP_PREFERRED >
115
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
115
116
fn drop ( & mut self ) {
116
- struct DropGuard < ' r , ' a , T , A : Allocator > ( & ' r mut Drain < ' a , T , A > )
117
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : ;
117
+ struct DropGuard < ' r , ' a , T , A : Allocator , const COOP_PREFERRED : bool > ( & ' r mut Drain < ' a , T , A , COOP_PREFERRED > )
118
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : ;
118
119
119
- impl < ' r , ' a , T , A : Allocator > Drop for DropGuard < ' r , ' a , T , A >
120
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
120
+ impl < ' r , ' a , T , A : Allocator , const COOP_PREFERRED : bool > Drop for DropGuard < ' r , ' a , T , A , COOP_PREFERRED >
121
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
121
122
fn drop ( & mut self ) {
122
123
if self . 0 . remaining != 0 {
123
124
unsafe {
@@ -198,8 +199,8 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
198
199
}
199
200
200
201
#[ stable( feature = "drain" , since = "1.6.0" ) ]
201
- impl < T , A : Allocator > Iterator for Drain < ' _ , T , A >
202
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
202
+ impl < T , A : Allocator , const COOP_PREFERRED : bool > Iterator for Drain < ' _ , T , A , COOP_PREFERRED >
203
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
203
204
type Item = T ;
204
205
205
206
#[ inline]
@@ -221,8 +222,8 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
221
222
}
222
223
223
224
#[ stable( feature = "drain" , since = "1.6.0" ) ]
224
- impl < T , A : Allocator > DoubleEndedIterator for Drain < ' _ , T , A >
225
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
225
+ impl < T , A : Allocator , const COOP_PREFERRED : bool > DoubleEndedIterator for Drain < ' _ , T , A , COOP_PREFERRED >
226
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
226
227
#[ inline]
227
228
fn next_back ( & mut self ) -> Option < T > {
228
229
if self . remaining == 0 {
@@ -235,9 +236,9 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
235
236
}
236
237
237
238
#[ stable( feature = "drain" , since = "1.6.0" ) ]
238
- impl < T , A : Allocator > ExactSizeIterator for Drain < ' _ , T , A >
239
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : { }
239
+ impl < T , A : Allocator , const COOP_PREFERRED : bool > ExactSizeIterator for Drain < ' _ , T , A , COOP_PREFERRED >
240
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : { }
240
241
241
242
#[ stable( feature = "fused" , since = "1.26.0" ) ]
242
- impl < T , A : Allocator > FusedIterator for Drain < ' _ , T , A >
243
- where [ ( ) ; alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : { }
243
+ impl < T , A : Allocator , const COOP_PREFERRED : bool > FusedIterator for Drain < ' _ , T , A , COOP_PREFERRED >
244
+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : { }
0 commit comments