@@ -1009,7 +1009,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
1009
1009
/// ```
1010
1010
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1011
1011
pub fn iter ( & self ) -> Iter < ' _ , T > {
1012
- Iter { tail : self . tail , head : self . head , ring : unsafe { self . buffer_as_slice ( ) } }
1012
+ Iter :: new ( unsafe { self . buffer_as_slice ( ) } , self . tail , self . head )
1013
1013
}
1014
1014
1015
1015
/// Returns a front-to-back iterator that returns mutable references.
@@ -1188,12 +1188,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
1188
1188
R : RangeBounds < usize > ,
1189
1189
{
1190
1190
let ( tail, head) = self . range_tail_head ( range) ;
1191
- Iter {
1192
- tail,
1193
- head,
1194
- // The shared reference we have in &self is maintained in the '_ of Iter.
1195
- ring : unsafe { self . buffer_as_slice ( ) } ,
1196
- }
1191
+ // The shared reference we have in &self is maintained in the '_ of Iter.
1192
+ Iter :: new ( unsafe { self . buffer_as_slice ( ) } , tail, head)
1197
1193
}
1198
1194
1199
1195
/// Creates an iterator that covers the specified mutable range in the deque.
@@ -1309,16 +1305,15 @@ impl<T, A: Allocator> VecDeque<T, A> {
1309
1305
self . head = drain_tail;
1310
1306
1311
1307
let deque = NonNull :: from ( & mut * self ) ;
1312
- let iter = Iter {
1313
- tail : drain_tail,
1314
- head : drain_head,
1308
+ unsafe {
1315
1309
// Crucially, we only create shared references from `self` here and read from
1316
1310
// it. We do not write to `self` nor reborrow to a mutable reference.
1317
1311
// Hence the raw pointer we created above, for `deque`, remains valid.
1318
- ring : unsafe { self . buffer_as_slice ( ) } ,
1319
- } ;
1312
+ let ring = self . buffer_as_slice ( ) ;
1313
+ let iter = Iter :: new ( ring , drain_tail , drain_head ) ;
1320
1314
1321
- unsafe { Drain :: new ( drain_head, head, iter, deque) }
1315
+ Drain :: new ( drain_head, head, iter, deque)
1316
+ }
1322
1317
}
1323
1318
1324
1319
/// Clears the deque, removing all values.
0 commit comments