1
1
use core:: iter:: FusedIterator ;
2
+ use crate :: co_alloc:: CoAllocPref ;
2
3
use core:: marker:: PhantomData ;
3
4
use core:: mem:: { self , SizedTypeProperties } ;
4
5
use core:: ptr:: NonNull ;
@@ -20,13 +21,13 @@ pub struct Drain<
20
21
' a ,
21
22
T : ' a ,
22
23
#[ unstable( feature = "allocator_api" , issue = "32838" ) ] A : Allocator = Global ,
23
- const COOP_PREF : bool = { SHORT_TERM_VEC_PREFERS_COOP ! ( ) } ,
24
+ const CO_ALLOC_PREF : CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP ! ( ) } ,
24
25
> where
25
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ,
26
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ,
26
27
{
27
28
// We can't just use a &mut VecDeque<T, A>, as that would make Drain invariant over T
28
29
// and we want it to be covariant instead
29
- deque : NonNull < VecDeque < T , A , COOP_PREF > > ,
30
+ deque : NonNull < VecDeque < T , A , CO_ALLOC_PREF > > ,
30
31
// drain_start is stored in deque.len
31
32
drain_len : usize ,
32
33
// index into the logical array, not the physical one (always lies in [0..deque.len))
@@ -38,12 +39,12 @@ pub struct Drain<
38
39
_marker : PhantomData < & ' a T > ,
39
40
}
40
41
41
- impl < ' a , T , A : Allocator , const COOP_PREF : bool > Drain < ' a , T , A , COOP_PREF >
42
+ impl < ' a , T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > Drain < ' a , T , A , CO_ALLOC_PREF >
42
43
where
43
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ,
44
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ,
44
45
{
45
46
pub ( super ) unsafe fn new (
46
- deque : & ' a mut VecDeque < T , A , COOP_PREF > ,
47
+ deque : & ' a mut VecDeque < T , A , CO_ALLOC_PREF > ,
47
48
drain_start : usize ,
48
49
drain_len : usize ,
49
50
) -> Self {
95
96
}
96
97
97
98
#[ stable( feature = "collection_debug" , since = "1.17.0" ) ]
98
- impl < T : fmt:: Debug , A : Allocator , const COOP_PREF : bool > fmt:: Debug for Drain < ' _ , T , A , COOP_PREF >
99
+ impl < T : fmt:: Debug , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > fmt:: Debug for Drain < ' _ , T , A , CO_ALLOC_PREF >
99
100
where
100
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ,
101
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ,
101
102
{
102
103
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
103
104
f. debug_tuple ( "Drain" )
@@ -110,31 +111,31 @@ where
110
111
}
111
112
112
113
#[ stable( feature = "drain" , since = "1.6.0" ) ]
113
- unsafe impl < T : Sync , A : Allocator + Sync , const COOP_PREF : bool > Sync for Drain < ' _ , T , A , COOP_PREF > where
114
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] :
114
+ unsafe impl < T : Sync , A : Allocator + Sync , const CO_ALLOC_PREF : CoAllocPref > Sync for Drain < ' _ , T , A , CO_ALLOC_PREF > where
115
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] :
115
116
{
116
117
}
117
118
#[ stable( feature = "drain" , since = "1.6.0" ) ]
118
- unsafe impl < T : Send , A : Allocator + Send , const COOP_PREF : bool > Send for Drain < ' _ , T , A , COOP_PREF > where
119
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] :
119
+ unsafe impl < T : Send , A : Allocator + Send , const CO_ALLOC_PREF : CoAllocPref > Send for Drain < ' _ , T , A , CO_ALLOC_PREF > where
120
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] :
120
121
{
121
122
}
122
123
123
124
#[ stable( feature = "drain" , since = "1.6.0" ) ]
124
- impl < T , A : Allocator , const COOP_PREF : bool > Drop for Drain < ' _ , T , A , COOP_PREF >
125
+ impl < T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > Drop for Drain < ' _ , T , A , CO_ALLOC_PREF >
125
126
where
126
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ,
127
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ,
127
128
{
128
129
fn drop ( & mut self ) {
129
- struct DropGuard < ' r , ' a , T , A : Allocator , const COOP_PREF : bool > (
130
- & ' r mut Drain < ' a , T , A , COOP_PREF > ,
130
+ struct DropGuard < ' r , ' a , T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > (
131
+ & ' r mut Drain < ' a , T , A , CO_ALLOC_PREF > ,
131
132
)
132
133
where
133
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ;
134
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ;
134
135
135
- impl < ' r , ' a , T , A : Allocator , const COOP_PREF : bool > Drop for DropGuard < ' r , ' a , T , A , COOP_PREF >
136
+ impl < ' r , ' a , T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > Drop for DropGuard < ' r , ' a , T , A , CO_ALLOC_PREF >
136
137
where
137
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ,
138
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ,
138
139
{
139
140
fn drop ( & mut self ) {
140
141
if self . 0 . remaining != 0 {
@@ -216,9 +217,9 @@ where
216
217
}
217
218
218
219
#[ stable( feature = "drain" , since = "1.6.0" ) ]
219
- impl < T , A : Allocator , const COOP_PREF : bool > Iterator for Drain < ' _ , T , A , COOP_PREF >
220
+ impl < T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > Iterator for Drain < ' _ , T , A , CO_ALLOC_PREF >
220
221
where
221
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ,
222
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ,
222
223
{
223
224
type Item = T ;
224
225
@@ -241,9 +242,9 @@ where
241
242
}
242
243
243
244
#[ stable( feature = "drain" , since = "1.6.0" ) ]
244
- impl < T , A : Allocator , const COOP_PREF : bool > DoubleEndedIterator for Drain < ' _ , T , A , COOP_PREF >
245
+ impl < T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > DoubleEndedIterator for Drain < ' _ , T , A , CO_ALLOC_PREF >
245
246
where
246
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] : ,
247
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] : ,
247
248
{
248
249
#[ inline]
249
250
fn next_back ( & mut self ) -> Option < T > {
@@ -257,13 +258,13 @@ where
257
258
}
258
259
259
260
#[ stable( feature = "drain" , since = "1.6.0" ) ]
260
- impl < T , A : Allocator , const COOP_PREF : bool > ExactSizeIterator for Drain < ' _ , T , A , COOP_PREF > where
261
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] :
261
+ impl < T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > ExactSizeIterator for Drain < ' _ , T , A , CO_ALLOC_PREF > where
262
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] :
262
263
{
263
264
}
264
265
265
266
#[ stable( feature = "fused" , since = "1.26.0" ) ]
266
- impl < T , A : Allocator , const COOP_PREF : bool > FusedIterator for Drain < ' _ , T , A , COOP_PREF > where
267
- [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREF ) ] :
267
+ impl < T , A : Allocator , const CO_ALLOC_PREF : CoAllocPref > FusedIterator for Drain < ' _ , T , A , CO_ALLOC_PREF > where
268
+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( CO_ALLOC_PREF ) ] :
268
269
{
269
270
}
0 commit comments