@@ -38,6 +38,7 @@ use cmp::{Ordering, PartialEq, PartialOrd, Eq, Ord};
38
38
use cmp:: Ordering :: { Less , Equal , Greater } ;
39
39
use cmp;
40
40
use default:: Default ;
41
+ use fmt;
41
42
use intrinsics:: assume;
42
43
use iter:: * ;
43
44
use ops:: { FnMut , self , Index } ;
@@ -632,8 +633,7 @@ impl<T> ops::Index<ops::RangeToInclusive<usize>> for [T] {
632
633
633
634
#[ inline]
634
635
fn index ( & self , index : ops:: RangeToInclusive < usize > ) -> & [ T ] {
635
- // SNAP 4d3eebf change this to `0...index.end`
636
- self . index ( ops:: RangeInclusive :: NonEmpty { start : 0 , end : index. end } )
636
+ self . index ( 0 ...index. end )
637
637
}
638
638
}
639
639
@@ -723,8 +723,7 @@ impl<T> ops::IndexMut<ops::RangeInclusive<usize>> for [T] {
723
723
impl < T > ops:: IndexMut < ops:: RangeToInclusive < usize > > for [ T ] {
724
724
#[ inline]
725
725
fn index_mut ( & mut self , index : ops:: RangeToInclusive < usize > ) -> & mut [ T ] {
726
- // SNAP 4d3eebf change this to `0...index.end`
727
- self . index_mut ( ops:: RangeInclusive :: NonEmpty { start : 0 , end : index. end } )
726
+ self . index_mut ( 0 ...index. end )
728
727
}
729
728
}
730
729
@@ -872,13 +871,36 @@ macro_rules! make_mut_slice {
872
871
}
873
872
874
873
/// Immutable slice iterator
874
+ ///
875
+ /// # Examples
876
+ ///
877
+ /// Basic usage:
878
+ ///
879
+ /// ```
880
+ /// // First, we declare a type which has `iter` method to get the `Iter` struct (&[usize here]):
881
+ /// let slice = &[1, 2, 3];
882
+ ///
883
+ /// // Then, we iterate over it:
884
+ /// for element in slice.iter() {
885
+ /// println!("{}", element);
886
+ /// }
887
+ /// ```
875
888
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
876
889
pub struct Iter < ' a , T : ' a > {
877
890
ptr : * const T ,
878
891
end : * const T ,
879
892
_marker : marker:: PhantomData < & ' a T > ,
880
893
}
881
894
895
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
896
+ impl < ' a , T : ' a + fmt:: Debug > fmt:: Debug for Iter < ' a , T > {
897
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
898
+ f. debug_tuple ( "Iter" )
899
+ . field ( & self . as_slice ( ) )
900
+ . finish ( )
901
+ }
902
+ }
903
+
882
904
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
883
905
unsafe impl < ' a , T : Sync > Sync for Iter < ' a , T > { }
884
906
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -889,6 +911,26 @@ impl<'a, T> Iter<'a, T> {
889
911
///
890
912
/// This has the same lifetime as the original slice, and so the
891
913
/// iterator can continue to be used while this exists.
914
+ ///
915
+ /// # Examples
916
+ ///
917
+ /// Basic usage:
918
+ ///
919
+ /// ```
920
+ /// // First, we declare a type which has the `iter` method to get the `Iter`
921
+ /// // struct (&[usize here]):
922
+ /// let slice = &[1, 2, 3];
923
+ ///
924
+ /// // Then, we get the iterator:
925
+ /// let mut iter = slice.iter();
926
+ /// // So if we print what `as_slice` method returns here, we have "[1, 2, 3]":
927
+ /// println!("{:?}", iter.as_slice());
928
+ ///
929
+ /// // Next, we move to the second element of the slice:
930
+ /// iter.next();
931
+ /// // Now `as_slice` returns "[2, 3]":
932
+ /// println!("{:?}", iter.as_slice());
933
+ /// ```
892
934
#[ stable( feature = "iter_to_slice" , since = "1.4.0" ) ]
893
935
pub fn as_slice ( & self ) -> & ' a [ T ] {
894
936
make_slice ! ( self . ptr, self . end)
@@ -920,13 +962,40 @@ impl<'a, T> Clone for Iter<'a, T> {
920
962
}
921
963
922
964
/// Mutable slice iterator.
965
+ ///
966
+ /// # Examples
967
+ ///
968
+ /// Basic usage:
969
+ ///
970
+ /// ```
971
+ /// // First, we declare a type which has `iter_mut` method to get the `IterMut`
972
+ /// // struct (&[usize here]):
973
+ /// let mut slice = &mut [1, 2, 3];
974
+ ///
975
+ /// // Then, we iterate over it and increment each element value:
976
+ /// for element in slice.iter_mut() {
977
+ /// *element += 1;
978
+ /// }
979
+ ///
980
+ /// // We now have "[2, 3, 4]":
981
+ /// println!("{:?}", slice);
982
+ /// ```
923
983
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
924
984
pub struct IterMut < ' a , T : ' a > {
925
985
ptr : * mut T ,
926
986
end : * mut T ,
927
987
_marker : marker:: PhantomData < & ' a mut T > ,
928
988
}
929
989
990
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
991
+ impl < ' a , T : ' a + fmt:: Debug > fmt:: Debug for IterMut < ' a , T > {
992
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
993
+ f. debug_tuple ( "IterMut" )
994
+ . field ( & make_slice ! ( self . ptr, self . end) )
995
+ . finish ( )
996
+ }
997
+ }
998
+
930
999
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
931
1000
unsafe impl < ' a , T : Sync > Sync for IterMut < ' a , T > { }
932
1001
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -939,6 +1008,35 @@ impl<'a, T> IterMut<'a, T> {
939
1008
/// to consume the iterator. Consider using the `Slice` and
940
1009
/// `SliceMut` implementations for obtaining slices with more
941
1010
/// restricted lifetimes that do not consume the iterator.
1011
+ ///
1012
+ /// # Examples
1013
+ ///
1014
+ /// Basic usage:
1015
+ ///
1016
+ /// ```
1017
+ /// // First, we declare a type which has `iter_mut` method to get the `IterMut`
1018
+ /// // struct (&[usize here]):
1019
+ /// let mut slice = &mut [1, 2, 3];
1020
+ ///
1021
+ /// {
1022
+ /// // Then, we get the iterator:
1023
+ /// let mut iter = slice.iter_mut();
1024
+ /// // We move to next element:
1025
+ /// iter.next();
1026
+ /// // So if we print what `into_slice` method returns here, we have "[2, 3]":
1027
+ /// println!("{:?}", iter.into_slice());
1028
+ /// }
1029
+ ///
1030
+ /// // Now let's modify a value of the slice:
1031
+ /// {
1032
+ /// // First we get back the iterator:
1033
+ /// let mut iter = slice.iter_mut();
1034
+ /// // We change the value of the first element of the slice returned by the `next` method:
1035
+ /// *iter.next().unwrap() += 1;
1036
+ /// }
1037
+ /// // Now slice is "[2, 2, 3]":
1038
+ /// println!("{:?}", slice);
1039
+ /// ```
942
1040
#[ stable( feature = "iter_to_slice" , since = "1.4.0" ) ]
943
1041
pub fn into_slice ( self ) -> & ' a mut [ T ] {
944
1042
make_mut_slice ! ( self . ptr, self . end)
@@ -982,6 +1080,16 @@ pub struct Split<'a, T:'a, P> where P: FnMut(&T) -> bool {
982
1080
finished : bool
983
1081
}
984
1082
1083
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
1084
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for Split < ' a , T , P > where P : FnMut ( & T ) -> bool {
1085
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1086
+ f. debug_struct ( "Split" )
1087
+ . field ( "v" , & self . v )
1088
+ . field ( "finished" , & self . finished )
1089
+ . finish ( )
1090
+ }
1091
+ }
1092
+
985
1093
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
986
1094
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
987
1095
impl < ' a , T , P > Clone for Split < ' a , T , P > where P : Clone + FnMut ( & T ) -> bool {
@@ -1055,6 +1163,16 @@ pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool {
1055
1163
finished : bool
1056
1164
}
1057
1165
1166
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
1167
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for SplitMut < ' a , T , P > where P : FnMut ( & T ) -> bool {
1168
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1169
+ f. debug_struct ( "SplitMut" )
1170
+ . field ( "v" , & self . v )
1171
+ . field ( "finished" , & self . finished )
1172
+ . finish ( )
1173
+ }
1174
+ }
1175
+
1058
1176
impl < ' a , T , P > SplitIter for SplitMut < ' a , T , P > where P : FnMut ( & T ) -> bool {
1059
1177
#[ inline]
1060
1178
fn finish ( & mut self ) -> Option < & ' a mut [ T ] > {
@@ -1129,6 +1247,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
1129
1247
/// An private iterator over subslices separated by elements that
1130
1248
/// match a predicate function, splitting at most a fixed number of
1131
1249
/// times.
1250
+ #[ derive( Debug ) ]
1132
1251
struct GenericSplitN < I > {
1133
1252
iter : I ,
1134
1253
count : usize ,
@@ -1164,6 +1283,15 @@ pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
1164
1283
inner : GenericSplitN < Split < ' a , T , P > >
1165
1284
}
1166
1285
1286
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
1287
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for SplitN < ' a , T , P > where P : FnMut ( & T ) -> bool {
1288
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1289
+ f. debug_struct ( "SplitN" )
1290
+ . field ( "inner" , & self . inner )
1291
+ . finish ( )
1292
+ }
1293
+ }
1294
+
1167
1295
/// An iterator over subslices separated by elements that match a
1168
1296
/// predicate function, limited to a given number of splits, starting
1169
1297
/// from the end of the slice.
@@ -1172,13 +1300,31 @@ pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
1172
1300
inner : GenericSplitN < Split < ' a , T , P > >
1173
1301
}
1174
1302
1303
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
1304
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for RSplitN < ' a , T , P > where P : FnMut ( & T ) -> bool {
1305
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1306
+ f. debug_struct ( "RSplitN" )
1307
+ . field ( "inner" , & self . inner )
1308
+ . finish ( )
1309
+ }
1310
+ }
1311
+
1175
1312
/// An iterator over subslices separated by elements that match a predicate
1176
1313
/// function, limited to a given number of splits.
1177
1314
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1178
1315
pub struct SplitNMut < ' a , T : ' a , P > where P : FnMut ( & T ) -> bool {
1179
1316
inner : GenericSplitN < SplitMut < ' a , T , P > >
1180
1317
}
1181
1318
1319
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
1320
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for SplitNMut < ' a , T , P > where P : FnMut ( & T ) -> bool {
1321
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1322
+ f. debug_struct ( "SplitNMut" )
1323
+ . field ( "inner" , & self . inner )
1324
+ . finish ( )
1325
+ }
1326
+ }
1327
+
1182
1328
/// An iterator over subslices separated by elements that match a
1183
1329
/// predicate function, limited to a given number of splits, starting
1184
1330
/// from the end of the slice.
@@ -1187,6 +1333,15 @@ pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool {
1187
1333
inner : GenericSplitN < SplitMut < ' a , T , P > >
1188
1334
}
1189
1335
1336
+ #[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
1337
+ impl < ' a , T : ' a + fmt:: Debug , P > fmt:: Debug for RSplitNMut < ' a , T , P > where P : FnMut ( & T ) -> bool {
1338
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1339
+ f. debug_struct ( "RSplitNMut" )
1340
+ . field ( "inner" , & self . inner )
1341
+ . finish ( )
1342
+ }
1343
+ }
1344
+
1190
1345
macro_rules! forward_iterator {
1191
1346
( $name: ident: $elem: ident, $iter_of: ty) => {
1192
1347
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1214,6 +1369,7 @@ forward_iterator! { SplitNMut: T, &'a mut [T] }
1214
1369
forward_iterator ! { RSplitNMut : T , & ' a mut [ T ] }
1215
1370
1216
1371
/// An iterator over overlapping subslices of length `size`.
1372
+ #[ derive( Debug ) ]
1217
1373
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1218
1374
pub struct Windows < ' a , T : ' a > {
1219
1375
v : & ' a [ T ] ,
@@ -1307,6 +1463,7 @@ impl<'a, T> ExactSizeIterator for Windows<'a, T> {}
1307
1463
///
1308
1464
/// When the slice len is not evenly divided by the chunk size, the last slice
1309
1465
/// of the iteration will be the remainder.
1466
+ #[ derive( Debug ) ]
1310
1467
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1311
1468
pub struct Chunks < ' a , T : ' a > {
1312
1469
v : & ' a [ T ] ,
@@ -1407,6 +1564,7 @@ impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
1407
1564
/// An iterator over a slice in (non-overlapping) mutable chunks (`size`
1408
1565
/// elements at a time). When the slice len is not evenly divided by the chunk
1409
1566
/// size, the last slice of the iteration will be the remainder.
1567
+ #[ derive( Debug ) ]
1410
1568
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1411
1569
pub struct ChunksMut < ' a , T : ' a > {
1412
1570
v : & ' a mut [ T ] ,
0 commit comments