@@ -1180,26 +1180,27 @@ pub trait Iterator {
1180
1180
///
1181
1181
/// // this iterator sequence is complex.
1182
1182
/// let sum = a.iter()
1183
- /// .cloned()
1184
- /// .filter(|& x| x % 2 == 0)
1185
- /// .fold(0, |sum, i| sum + i);
1183
+ /// .cloned()
1184
+ /// .filter(|x| x % 2 == 0)
1185
+ /// .fold(0, |sum, i| sum + i);
1186
1186
///
1187
1187
/// println!("{}", sum);
1188
1188
///
1189
1189
/// // let's add some inspect() calls to investigate what's happening
1190
1190
/// let sum = a.iter()
1191
- /// .cloned()
1192
- /// .inspect(|x| println!("about to filter: {}", x))
1193
- /// .filter(|& x| x % 2 == 0)
1194
- /// .inspect(|x| println!("made it through filter: {}", x))
1195
- /// .fold(0, |sum, i| sum + i);
1191
+ /// .cloned()
1192
+ /// .inspect(|x| println!("about to filter: {}", x))
1193
+ /// .filter(|x| x % 2 == 0)
1194
+ /// .inspect(|x| println!("made it through filter: {}", x))
1195
+ /// .fold(0, |sum, i| sum + i);
1196
1196
///
1197
1197
/// println!("{}", sum);
1198
1198
/// ```
1199
1199
///
1200
1200
/// This will print:
1201
1201
///
1202
1202
/// ```text
1203
+ /// 6
1203
1204
/// about to filter: 1
1204
1205
/// about to filter: 4
1205
1206
/// made it through filter: 4
@@ -1230,8 +1231,7 @@ pub trait Iterator {
1230
1231
///
1231
1232
/// let iter = a.into_iter();
1232
1233
///
1233
- /// let sum: i32 = iter.take(5)
1234
- /// .fold(0, |acc, &i| acc + i );
1234
+ /// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i );
1235
1235
///
1236
1236
/// assert_eq!(sum, 6);
1237
1237
///
@@ -1245,9 +1245,7 @@ pub trait Iterator {
1245
1245
/// let mut iter = a.into_iter();
1246
1246
///
1247
1247
/// // instead, we add in a .by_ref()
1248
- /// let sum: i32 = iter.by_ref()
1249
- /// .take(2)
1250
- /// .fold(0, |acc, &i| acc + i );
1248
+ /// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i );
1251
1249
///
1252
1250
/// assert_eq!(sum, 3);
1253
1251
///
@@ -1304,9 +1302,7 @@ pub trait Iterator {
1304
1302
///
1305
1303
/// let a = [1, 2, 3];
1306
1304
///
1307
- /// let doubled: VecDeque<i32> = a.iter()
1308
- /// .map(|&x| x * 2)
1309
- /// .collect();
1305
+ /// let doubled: VecDeque<i32> = a.iter().map(|&x| x * 2).collect();
1310
1306
///
1311
1307
/// assert_eq!(2, doubled[0]);
1312
1308
/// assert_eq!(4, doubled[1]);
@@ -1318,9 +1314,7 @@ pub trait Iterator {
1318
1314
/// ```
1319
1315
/// let a = [1, 2, 3];
1320
1316
///
1321
- /// let doubled = a.iter()
1322
- /// .map(|&x| x * 2)
1323
- /// .collect::<Vec<i32>>();
1317
+ /// let doubled = a.iter().map(|x| x * 2).collect::<Vec<i32>>();
1324
1318
///
1325
1319
/// assert_eq!(vec![2, 4, 6], doubled);
1326
1320
/// ```
@@ -1331,9 +1325,7 @@ pub trait Iterator {
1331
1325
/// ```
1332
1326
/// let a = [1, 2, 3];
1333
1327
///
1334
- /// let doubled = a.iter()
1335
- /// .map(|&x| x * 2)
1336
- /// .collect::<Vec<_>>();
1328
+ /// let doubled = a.iter().map(|x| x * 2).collect::<Vec<_>>();
1337
1329
///
1338
1330
/// assert_eq!(vec![2, 4, 6], doubled);
1339
1331
/// ```
@@ -1344,9 +1336,9 @@ pub trait Iterator {
1344
1336
/// let chars = ['g', 'd', 'k', 'k', 'n'];
1345
1337
///
1346
1338
/// let hello: String = chars.iter()
1347
- /// .map(|&x| x as u8)
1348
- /// .map(|x| (x + 1) as char)
1349
- /// .collect();
1339
+ /// .map(|&x| x as u8)
1340
+ /// .map(|x| (x + 1) as char)
1341
+ /// .collect();
1350
1342
///
1351
1343
/// assert_eq!("hello", hello);
1352
1344
/// ```
@@ -1393,8 +1385,9 @@ pub trait Iterator {
1393
1385
/// ```
1394
1386
/// let a = [1, 2, 3];
1395
1387
///
1396
- /// let (even, odd): (Vec<i32>, Vec<i32>) = a.into_iter()
1397
- /// .partition(|&n| n % 2 == 0);
1388
+ /// let (even, odd): (Vec<i32>, Vec<i32>) = a
1389
+ /// .into_iter()
1390
+ /// .partition(|&n| n % 2 == 0);
1398
1391
///
1399
1392
/// assert_eq!(even, vec![2]);
1400
1393
/// assert_eq!(odd, vec![1, 3]);
@@ -1457,8 +1450,7 @@ pub trait Iterator {
1457
1450
/// let a = [1, 2, 3];
1458
1451
///
1459
1452
/// // the checked sum of all of the elements of the array
1460
- /// let sum = a.iter()
1461
- /// .try_fold(0i8, |acc, &x| acc.checked_add(x));
1453
+ /// let sum = a.iter().try_fold(0i8, |acc, &x| acc.checked_add(x));
1462
1454
///
1463
1455
/// assert_eq!(sum, Some(6));
1464
1456
/// ```
@@ -1556,8 +1548,7 @@ pub trait Iterator {
1556
1548
/// let a = [1, 2, 3];
1557
1549
///
1558
1550
/// // the sum of all of the elements of the array
1559
- /// let sum = a.iter()
1560
- /// .fold(0, |acc, &x| acc + x);
1551
+ /// let sum = a.iter().fold(0, |acc, x| acc + x);
1561
1552
///
1562
1553
/// assert_eq!(sum, 6);
1563
1554
/// ```
0 commit comments