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