@@ -469,9 +469,9 @@ impl<T> VecDeque<T> {
469
469
/// buf.push_back(3);
470
470
/// buf.push_back(4);
471
471
/// buf.push_back(5);
472
+ /// assert_eq!(buf, [3, 4, 5]);
472
473
/// buf.swap(0, 2);
473
- /// assert_eq!(buf[0], 5);
474
- /// assert_eq!(buf[2], 3);
474
+ /// assert_eq!(buf, [5, 4, 3]);
475
475
/// ```
476
476
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
477
477
pub fn swap ( & mut self , i : usize , j : usize ) {
@@ -649,9 +649,9 @@ impl<T> VecDeque<T> {
649
649
/// buf.push_back(5);
650
650
/// buf.push_back(10);
651
651
/// buf.push_back(15);
652
+ /// assert_eq!(buf, [5, 10, 15]);
652
653
/// buf.truncate(1);
653
- /// assert_eq!(buf.len(), 1);
654
- /// assert_eq!(Some(&5), buf.get(0));
654
+ /// assert_eq!(buf, [5]);
655
655
/// ```
656
656
#[ stable( feature = "deque_extras" , since = "1.16.0" ) ]
657
657
pub fn truncate ( & mut self , len : usize ) {
@@ -826,8 +826,9 @@ impl<T> VecDeque<T> {
826
826
/// use std::collections::VecDeque;
827
827
///
828
828
/// let mut v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
829
- /// assert_eq!(vec![3].into_iter().collect::<VecDeque<_>>(), v.drain(2..).collect());
830
- /// assert_eq!(vec![1, 2].into_iter().collect::<VecDeque<_>>(), v);
829
+ /// let drained = v.drain(2..).collect::<VecDeque<_>>();
830
+ /// assert_eq!(drained, [3]);
831
+ /// assert_eq!(v, [1, 2]);
831
832
///
832
833
/// // A full range clears all contents
833
834
/// v.drain(..);
@@ -1179,11 +1180,10 @@ impl<T> VecDeque<T> {
1179
1180
/// buf.push_back(1);
1180
1181
/// buf.push_back(2);
1181
1182
/// buf.push_back(3);
1183
+ /// assert_eq!(buf, [1, 2, 3]);
1182
1184
///
1183
1185
/// assert_eq!(buf.swap_remove_back(0), Some(1));
1184
- /// assert_eq!(buf.len(), 2);
1185
- /// assert_eq!(buf[0], 3);
1186
- /// assert_eq!(buf[1], 2);
1186
+ /// assert_eq!(buf, [3, 2]);
1187
1187
/// ```
1188
1188
#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
1189
1189
pub fn swap_remove_back ( & mut self , index : usize ) -> Option < T > {
@@ -1215,11 +1215,10 @@ impl<T> VecDeque<T> {
1215
1215
/// buf.push_back(1);
1216
1216
/// buf.push_back(2);
1217
1217
/// buf.push_back(3);
1218
+ /// assert_eq!(buf, [1, 2, 3]);
1218
1219
///
1219
1220
/// assert_eq!(buf.swap_remove_front(2), Some(3));
1220
- /// assert_eq!(buf.len(), 2);
1221
- /// assert_eq!(buf[0], 2);
1222
- /// assert_eq!(buf[1], 1);
1221
+ /// assert_eq!(buf, [2, 1]);
1223
1222
/// ```
1224
1223
#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
1225
1224
pub fn swap_remove_front ( & mut self , index : usize ) -> Option < T > {
@@ -1250,11 +1249,10 @@ impl<T> VecDeque<T> {
1250
1249
/// vec_deque.push_back('a');
1251
1250
/// vec_deque.push_back('b');
1252
1251
/// vec_deque.push_back('c');
1252
+ /// assert_eq!(vec_deque, &['a', 'b', 'c']);
1253
1253
///
1254
1254
/// vec_deque.insert(1, 'd');
1255
- ///
1256
- /// let vec = vec_deque.into_iter().collect::<Vec<_>>();
1257
- /// assert_eq!(vec, ['a', 'd', 'b', 'c']);
1255
+ /// assert_eq!(vec_deque, &['a', 'd', 'b', 'c']);
1258
1256
/// ```
1259
1257
#[ stable( feature = "deque_extras_15" , since = "1.5.0" ) ]
1260
1258
pub fn insert ( & mut self , index : usize , value : T ) {
@@ -1478,9 +1476,10 @@ impl<T> VecDeque<T> {
1478
1476
/// buf.push_back(1);
1479
1477
/// buf.push_back(2);
1480
1478
/// buf.push_back(3);
1479
+ /// assert_eq!(buf, [1, 2, 3]);
1481
1480
///
1482
1481
/// assert_eq!(buf.remove(1), Some(2));
1483
- /// assert_eq!(buf.get(1), Some(&3) );
1482
+ /// assert_eq!(buf, [1, 3] );
1484
1483
/// ```
1485
1484
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1486
1485
pub fn remove ( & mut self , index : usize ) -> Option < T > {
@@ -1659,9 +1658,8 @@ impl<T> VecDeque<T> {
1659
1658
///
1660
1659
/// let mut buf: VecDeque<_> = vec![1,2,3].into_iter().collect();
1661
1660
/// let buf2 = buf.split_off(1);
1662
- /// // buf = [1], buf2 = [2, 3]
1663
- /// assert_eq!(buf.len(), 1);
1664
- /// assert_eq!(buf2.len(), 2);
1661
+ /// assert_eq!(buf, [1]);
1662
+ /// assert_eq!(buf2, [2, 3]);
1665
1663
/// ```
1666
1664
#[ inline]
1667
1665
#[ stable( feature = "split_off" , since = "1.4.0" ) ]
@@ -1718,11 +1716,11 @@ impl<T> VecDeque<T> {
1718
1716
/// ```
1719
1717
/// use std::collections::VecDeque;
1720
1718
///
1721
- /// let mut buf: VecDeque<_> = vec![1, 2, 3 ].into_iter().collect();
1722
- /// let mut buf2: VecDeque<_> = vec![4, 5, 6 ].into_iter().collect();
1719
+ /// let mut buf: VecDeque<_> = vec![1, 2].into_iter().collect();
1720
+ /// let mut buf2: VecDeque<_> = vec![3, 4 ].into_iter().collect();
1723
1721
/// buf.append(&mut buf2);
1724
- /// assert_eq!(buf.len(), 6 );
1725
- /// assert_eq!(buf2.len(), 0 );
1722
+ /// assert_eq!(buf, [1, 2, 3, 4] );
1723
+ /// assert_eq!(buf2, [] );
1726
1724
/// ```
1727
1725
#[ inline]
1728
1726
#[ stable( feature = "append" , since = "1.4.0" ) ]
@@ -1745,9 +1743,7 @@ impl<T> VecDeque<T> {
1745
1743
/// let mut buf = VecDeque::new();
1746
1744
/// buf.extend(1..5);
1747
1745
/// buf.retain(|&x| x%2 == 0);
1748
- ///
1749
- /// let v: Vec<_> = buf.into_iter().collect();
1750
- /// assert_eq!(&v[..], &[2, 4]);
1746
+ /// assert_eq!(buf, [2, 4]);
1751
1747
/// ```
1752
1748
#[ stable( feature = "vec_deque_retain" , since = "1.4.0" ) ]
1753
1749
pub fn retain < F > ( & mut self , mut f : F )
@@ -1781,11 +1777,13 @@ impl<T: Clone> VecDeque<T> {
1781
1777
/// buf.push_back(5);
1782
1778
/// buf.push_back(10);
1783
1779
/// buf.push_back(15);
1780
+ /// assert_eq!(buf, [5, 10, 15]);
1781
+ ///
1784
1782
/// buf.resize(2, 0);
1785
- /// buf.resize(6, 20 );
1786
- /// for (a, b) in [5, 10, 20, 20, 20, 20].iter().zip(&buf) {
1787
- /// assert_eq!(a, b );
1788
- /// }
1783
+ /// assert_eq!(buf, [5, 10] );
1784
+ ///
1785
+ /// buf.resize(5, 20 );
1786
+ /// assert_eq!(buf, [5, 10, 20, 20, 20]);
1789
1787
/// ```
1790
1788
#[ stable( feature = "deque_extras" , since = "1.16.0" ) ]
1791
1789
pub fn resize ( & mut self , new_len : usize , value : T ) {
@@ -2162,6 +2160,46 @@ impl<A: PartialEq> PartialEq for VecDeque<A> {
2162
2160
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2163
2161
impl < A : Eq > Eq for VecDeque < A > { }
2164
2162
2163
+ macro_rules! __impl_slice_eq1 {
2164
+ ( $Lhs: ty, $Rhs: ty) => {
2165
+ __impl_slice_eq1! { $Lhs, $Rhs, Sized }
2166
+ } ;
2167
+ ( $Lhs: ty, $Rhs: ty, $Bound: ident) => {
2168
+ #[ stable( feature = "vec-deque-partial-eq-slice" , since = "1.16.0" ) ]
2169
+ impl <' a, ' b, A : $Bound, B > PartialEq <$Rhs> for $Lhs where A : PartialEq <B > {
2170
+ fn eq( & self , other: & $Rhs) -> bool {
2171
+ if self . len( ) != other. len( ) {
2172
+ return false ;
2173
+ }
2174
+ let ( sa, sb) = self . as_slices( ) ;
2175
+ let ( oa, ob) = other[ ..] . split_at( sa. len( ) ) ;
2176
+ sa == oa && sb == ob
2177
+ }
2178
+ }
2179
+ }
2180
+ }
2181
+
2182
+ __impl_slice_eq1 ! { VecDeque <A >, Vec <B > }
2183
+ __impl_slice_eq1 ! { VecDeque <A >, & ' b [ B ] }
2184
+ __impl_slice_eq1 ! { VecDeque <A >, & ' b mut [ B ] }
2185
+
2186
+ macro_rules! array_impls {
2187
+ ( $( $N: expr) +) => {
2188
+ $(
2189
+ __impl_slice_eq1! { VecDeque <A >, [ B ; $N] }
2190
+ __impl_slice_eq1! { VecDeque <A >, & ' b [ B ; $N] }
2191
+ __impl_slice_eq1! { VecDeque <A >, & ' b mut [ B ; $N] }
2192
+ ) +
2193
+ }
2194
+ }
2195
+
2196
+ array_impls ! {
2197
+ 0 1 2 3 4 5 6 7 8 9
2198
+ 10 11 12 13 14 15 16 17 18 19
2199
+ 20 21 22 23 24 25 26 27 28 29
2200
+ 30 31 32
2201
+ }
2202
+
2165
2203
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2166
2204
impl < A : PartialOrd > PartialOrd for VecDeque < A > {
2167
2205
fn partial_cmp ( & self , other : & VecDeque < A > ) -> Option < Ordering > {
@@ -2434,7 +2472,7 @@ mod tests {
2434
2472
let final_len = usable_cap / 2 ;
2435
2473
2436
2474
for len in 0 ..final_len {
2437
- let expected = if back {
2475
+ let expected: VecDeque < _ > = if back {
2438
2476
( 0 ..len) . collect ( )
2439
2477
} else {
2440
2478
( 0 ..len) . rev ( ) . collect ( )
@@ -2483,7 +2521,7 @@ mod tests {
2483
2521
// len is the length *after* insertion
2484
2522
for len in 1 ..cap {
2485
2523
// 0, 1, 2, .., len - 1
2486
- let expected = ( 0 ..) . take ( len) . collect ( ) ;
2524
+ let expected = ( 0 ..) . take ( len) . collect :: < VecDeque < _ > > ( ) ;
2487
2525
for tail_pos in 0 ..cap {
2488
2526
for to_insert in 0 ..len {
2489
2527
tester. tail = tail_pos;
@@ -2516,7 +2554,7 @@ mod tests {
2516
2554
// len is the length *after* removal
2517
2555
for len in 0 ..cap - 1 {
2518
2556
// 0, 1, 2, .., len - 1
2519
- let expected = ( 0 ..) . take ( len) . collect ( ) ;
2557
+ let expected = ( 0 ..) . take ( len) . collect :: < VecDeque < _ > > ( ) ;
2520
2558
for tail_pos in 0 ..cap {
2521
2559
for to_remove in 0 ..len + 1 {
2522
2560
tester. tail = tail_pos;
@@ -2591,7 +2629,7 @@ mod tests {
2591
2629
2592
2630
for len in 0 ..cap + 1 {
2593
2631
// 0, 1, 2, .., len - 1
2594
- let expected = ( 0 ..) . take ( len) . collect ( ) ;
2632
+ let expected = ( 0 ..) . take ( len) . collect :: < VecDeque < _ > > ( ) ;
2595
2633
for tail_pos in 0 ..max_cap + 1 {
2596
2634
tester. tail = tail_pos;
2597
2635
tester. head = tail_pos;
@@ -2624,9 +2662,9 @@ mod tests {
2624
2662
// index to split at
2625
2663
for at in 0 ..len + 1 {
2626
2664
// 0, 1, 2, .., at - 1 (may be empty)
2627
- let expected_self = ( 0 ..) . take ( at) . collect ( ) ;
2665
+ let expected_self = ( 0 ..) . take ( at) . collect :: < VecDeque < _ > > ( ) ;
2628
2666
// at, at + 1, .., len - 1 (may be empty)
2629
- let expected_other = ( at..) . take ( len - at) . collect ( ) ;
2667
+ let expected_other = ( at..) . take ( len - at) . collect :: < VecDeque < _ > > ( ) ;
2630
2668
2631
2669
for tail_pos in 0 ..cap {
2632
2670
tester. tail = tail_pos;
0 commit comments