@@ -751,6 +751,7 @@ impl<A, B, T: ExactSize<A>, U: ExactSize<B>> ExactSize<(A, B)> for Zip<T, U> {}
751
751
752
752
/// An double-ended iterator with the direction inverted
753
753
#[ deriving( Clone ) ]
754
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
754
755
pub struct Rev < T > {
755
756
iter : T
756
757
}
@@ -779,6 +780,7 @@ impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterato
779
780
}
780
781
781
782
/// A mutable reference to an iterator
783
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
782
784
pub struct ByRef < ' a , T > {
783
785
iter : & ' a mut T
784
786
}
@@ -1039,6 +1041,7 @@ impl<A, T: Clone + Iterator<A>> CloneableIterator for T {
1039
1041
1040
1042
/// An iterator that repeats endlessly
1041
1043
#[ deriving( Clone ) ]
1044
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1042
1045
pub struct Cycle < T > {
1043
1046
orig : T ,
1044
1047
iter : T ,
@@ -1090,6 +1093,7 @@ impl<A, T: Clone + RandomAccessIterator<A>> RandomAccessIterator<A> for Cycle<T>
1090
1093
1091
1094
/// An iterator which strings two iterators together
1092
1095
#[ deriving( Clone ) ]
1096
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1093
1097
pub struct Chain < T , U > {
1094
1098
a : T ,
1095
1099
b : U ,
@@ -1159,6 +1163,7 @@ for Chain<T, U> {
1159
1163
1160
1164
/// An iterator which iterates two other iterators simultaneously
1161
1165
#[ deriving( Clone ) ]
1166
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1162
1167
pub struct Zip < T , U > {
1163
1168
a : T ,
1164
1169
b : U
@@ -1237,6 +1242,7 @@ RandomAccessIterator<(A, B)> for Zip<T, U> {
1237
1242
}
1238
1243
1239
1244
/// An iterator which maps the values of `iter` with `f`
1245
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1240
1246
pub struct Map < ' a , A , B , T > {
1241
1247
iter : T ,
1242
1248
f : |A |: ' a -> B
@@ -1287,6 +1293,7 @@ impl<'a, A, B, T: RandomAccessIterator<A>> RandomAccessIterator<B> for Map<'a, A
1287
1293
}
1288
1294
1289
1295
/// An iterator which filters the elements of `iter` with `predicate`
1296
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1290
1297
pub struct Filter < ' a , A , T > {
1291
1298
iter : T ,
1292
1299
predicate : |& A |: ' a -> bool
@@ -1331,6 +1338,7 @@ impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Filter<'a, A,
1331
1338
}
1332
1339
1333
1340
/// An iterator which uses `f` to both filter and map elements from `iter`
1341
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1334
1342
pub struct FilterMap < ' a , A , B , T > {
1335
1343
iter : T ,
1336
1344
f : |A |: ' a -> Option <B >
@@ -1375,6 +1383,7 @@ for FilterMap<'a, A, B, T> {
1375
1383
1376
1384
/// An iterator which yields the current count and the element during iteration
1377
1385
#[ deriving( Clone ) ]
1386
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1378
1387
pub struct Enumerate < T > {
1379
1388
iter : T ,
1380
1389
count : uint
@@ -1429,6 +1438,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<(uint, A)> for Enumerat
1429
1438
}
1430
1439
1431
1440
/// An iterator with a `peek()` that returns an optional reference to the next element.
1441
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1432
1442
pub struct Peekable < A , T > {
1433
1443
iter : T ,
1434
1444
peeked : Option < A > ,
@@ -1479,6 +1489,7 @@ impl<'a, A, T: Iterator<A>> Peekable<A, T> {
1479
1489
}
1480
1490
1481
1491
/// An iterator which rejects elements while `predicate` is true
1492
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1482
1493
pub struct SkipWhile < ' a , A , T > {
1483
1494
iter : T ,
1484
1495
flag : bool ,
@@ -1517,6 +1528,7 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for SkipWhile<'a, A, T> {
1517
1528
}
1518
1529
1519
1530
/// An iterator which only accepts elements while `predicate` is true
1531
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1520
1532
pub struct TakeWhile < ' a , A , T > {
1521
1533
iter : T ,
1522
1534
flag : bool ,
@@ -1552,6 +1564,7 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for TakeWhile<'a, A, T> {
1552
1564
1553
1565
/// An iterator which skips over `n` elements of `iter`.
1554
1566
#[ deriving( Clone ) ]
1567
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1555
1568
pub struct Skip < T > {
1556
1569
iter : T ,
1557
1570
n : uint
@@ -1616,6 +1629,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Skip<T> {
1616
1629
1617
1630
/// An iterator which only iterates over the first `n` iterations of `iter`.
1618
1631
#[ deriving( Clone ) ]
1632
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1619
1633
pub struct Take < T > {
1620
1634
iter : T ,
1621
1635
n : uint
@@ -1665,6 +1679,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Take<T> {
1665
1679
1666
1680
1667
1681
/// An iterator to maintain state while iterating another iterator
1682
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1668
1683
pub struct Scan < ' a , A , B , T , St > {
1669
1684
iter : T ,
1670
1685
f : |& mut St , A |: ' a -> Option <B >,
@@ -1689,6 +1704,7 @@ impl<'a, A, B, T: Iterator<A>, St> Iterator<B> for Scan<'a, A, B, T, St> {
1689
1704
/// An iterator that maps each element to an iterator,
1690
1705
/// and yields the elements of the produced iterators
1691
1706
///
1707
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1692
1708
pub struct FlatMap < ' a , A , T , U > {
1693
1709
iter : T ,
1694
1710
f : |A |: ' a -> U ,
@@ -1748,6 +1764,7 @@ impl<'a,
1748
1764
/// An iterator that yields `None` forever after the underlying iterator
1749
1765
/// yields `None` once.
1750
1766
#[ deriving( Clone ) ]
1767
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1751
1768
pub struct Fuse < T > {
1752
1769
iter : T ,
1753
1770
done : bool
@@ -1820,6 +1837,7 @@ impl<T> Fuse<T> {
1820
1837
1821
1838
/// An iterator that calls a function with a reference to each
1822
1839
/// element before yielding it.
1840
+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1823
1841
pub struct Inspect < ' a , A , T > {
1824
1842
iter : T ,
1825
1843
f : |& A |: ' a
@@ -2299,4 +2317,3 @@ pub mod order {
2299
2317
}
2300
2318
}
2301
2319
}
2302
-
0 commit comments