diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index 52f1af2cc..e53659f5d 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -28,6 +28,7 @@ macro_rules! clone_fields { /// /// See [`.interleave()`](../trait.Itertools.html#method.interleave) for more information. #[derive(Clone, Debug)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Interleave { a: Fuse, b: Fuse, @@ -90,6 +91,7 @@ impl Iterator for Interleave /// See [`.interleave_shortest()`](../trait.Itertools.html#method.interleave_shortest) /// for more information. #[derive(Clone, Debug)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct InterleaveShortest where I: Iterator, J: Iterator @@ -267,6 +269,7 @@ impl Iterator for PutBack /// Iterator element type is `(I::Item, J::Item)`. /// /// See [`.cartesian_product()`](../trait.Itertools.html#method.cartesian_product) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Product where I: Iterator { @@ -362,6 +365,7 @@ impl Iterator for Product /// /// See [`.batching()`](../trait.Itertools.html#method.batching) for more information. #[derive(Clone)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Batching { f: F, iter: I, @@ -401,6 +405,7 @@ impl Iterator for Batching /// /// See [`.step()`](../trait.Itertools.html#method.step) for more information. #[derive(Clone, Debug)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Step { iter: Fuse, skip: usize, @@ -514,6 +519,7 @@ impl MergeCore /// Iterator element type is `I::Item`. /// /// See [`.merge()`](../trait.Itertools.html#method.merge_by) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Merge where I: Iterator, J: Iterator @@ -586,6 +592,7 @@ impl Iterator for Merge /// Iterator element type is `I::Item`. /// /// See [`.merge_by()`](../trait.Itertools.html#method.merge_by) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct MergeBy where I: Iterator, J: Iterator @@ -686,6 +693,7 @@ impl CoalesceCore /// An iterator adaptor that may join together adjacent elements. /// /// See [`.coalesce()`](../trait.Itertools.html#method.coalesce) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Coalesce where I: Iterator { @@ -740,6 +748,7 @@ impl Iterator for Coalesce /// An iterator adaptor that removes repeated duplicates. /// /// See [`.dedup()`](../trait.Itertools.html#method.dedup) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Dedup where I: Iterator { @@ -812,6 +821,7 @@ impl Iterator for Dedup /// to only pick off elements while the predicate returns `true`. /// /// See [`.take_while_ref()`](../trait.Itertools.html#method.take_while_ref) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct TakeWhileRef<'a, I: 'a, F> { iter: &'a mut I, f: F, @@ -862,6 +872,7 @@ impl<'a, I, F> Iterator for TakeWhileRef<'a, I, F> /// /// See [`.while_some()`](../trait.Itertools.html#method.while_some) for more information. #[derive(Clone, Debug)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct WhileSome { iter: I, } @@ -895,6 +906,7 @@ impl Iterator for WhileSome /// See [`.tuple_combinations()`](../trait.Itertools.html#method.tuple_combinations) for more /// information. #[derive(Debug)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct TupleCombinations where I: Iterator, T: HasCombination @@ -1023,6 +1035,7 @@ impl_tuple_combination!(Tuple4Combination Tuple3Combination ; A, A, A, A, A; a b /// /// See [`.flatten()`](../trait.Itertools.html#method.flatten) for more information. #[derive(Clone, Debug)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Flatten { iter: I, front: Option, @@ -1074,6 +1087,7 @@ impl Iterator for Flatten /// An iterator adapter to apply a transformation within a nested `Result`. /// /// See [`.map_results()`](../trait.Itertools.html#method.map_results) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct MapResults { iter: I, f: F @@ -1108,6 +1122,7 @@ impl Iterator for MapResults /// An iterator adapter to get the positions of each element that matches a predicate. /// /// See [`.positions()`](../trait.Itertools.html#method.positions) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Positions { iter: I, f: F, diff --git a/src/combinations.rs b/src/combinations.rs index 8199724a4..a7744151c 100644 --- a/src/combinations.rs +++ b/src/combinations.rs @@ -5,6 +5,7 @@ use std::fmt; /// An iterator to iterate through all the `n`-length combinations in an iterator. /// /// See [`.combinations()`](../trait.Itertools.html#method.combinations) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Combinations { n: usize, indices: Vec, diff --git a/src/groupbylazy.rs b/src/groupbylazy.rs index 0cf8a9cdd..96f751315 100644 --- a/src/groupbylazy.rs +++ b/src/groupbylazy.rs @@ -284,6 +284,7 @@ impl GroupInner /// iterated. /// /// See [`.group_by()`](../trait.Itertools.html#method.group_by) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct GroupBy where I: Iterator, { @@ -458,6 +459,7 @@ pub fn new_chunks(iter: J, size: usize) -> IntoChunks /// Iterator element type is `Chunk`, each chunk's iterator. /// /// See [`.chunks()`](../trait.Itertools.html#method.chunks) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct IntoChunks where I: Iterator, { diff --git a/src/intersperse.rs b/src/intersperse.rs index 339f868b5..b01de2486 100644 --- a/src/intersperse.rs +++ b/src/intersperse.rs @@ -10,6 +10,7 @@ use super::size_hint; /// This iterator is *fused*. /// /// See [`.intersperse()`](../trait.Itertools.html#method.intersperse) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Intersperse where I: Iterator { diff --git a/src/kmerge_impl.rs b/src/kmerge_impl.rs index 9ac8b63cc..029234778 100644 --- a/src/kmerge_impl.rs +++ b/src/kmerge_impl.rs @@ -109,6 +109,7 @@ fn sift_down(heap: &mut [T], index: usize, mut less_than: S) /// Iterator element type is `I::Item`. /// /// See [`.kmerge()`](../trait.Itertools.html#method.kmerge) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct KMerge where I: Iterator { @@ -183,6 +184,7 @@ impl Iterator for KMerge /// /// See [`.kmerge_by()`](../trait.Itertools.html#method.kmerge_by) for more /// information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct KMergeBy where I: Iterator, { diff --git a/src/pad_tail.rs b/src/pad_tail.rs index dc1a1a894..c9cfe6af3 100644 --- a/src/pad_tail.rs +++ b/src/pad_tail.rs @@ -8,6 +8,7 @@ use size_hint; /// /// See [`.pad_using()`](../trait.Itertools.html#method.pad_using) for more information. #[derive(Clone)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct PadUsing { iter: Fuse, min: usize, diff --git a/src/peeking_take_while.rs b/src/peeking_take_while.rs index 6e9ddd333..0b2291dfd 100644 --- a/src/peeking_take_while.rs +++ b/src/peeking_take_while.rs @@ -76,6 +76,7 @@ impl PeekingNext for PutBackN /// /// See [`.peeking_take_while()`](../trait.Itertools.html#method.peeking_take_while) /// for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct PeekingTakeWhile<'a, I: 'a, F> where I: Iterator, { diff --git a/src/tee.rs b/src/tee.rs index 79ce1a5eb..d6968fa92 100644 --- a/src/tee.rs +++ b/src/tee.rs @@ -15,6 +15,7 @@ struct TeeBuffer { /// One half of an iterator pair where both return the same elements. /// /// See [`.tee()`](../trait.Itertools.html#method.tee) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Tee where I: Iterator { diff --git a/src/tuple_impl.rs b/src/tuple_impl.rs index ae3aeae84..2f3fc0583 100644 --- a/src/tuple_impl.rs +++ b/src/tuple_impl.rs @@ -60,6 +60,7 @@ impl ExactSizeIterator for TupleBuffer /// An iterator that groups the items in tuples of a specific size. /// /// See [`.tuples()`](../trait.Itertools.html#method.tuples) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Tuples where I: Iterator, T: TupleCollect @@ -114,6 +115,7 @@ impl Tuples /// /// See [`.tuple_windows()`](../trait.Itertools.html#method.tuple_windows) for more /// information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct TupleWindows where I: Iterator, T: TupleCollect diff --git a/src/unique_impl.rs b/src/unique_impl.rs index 469400a11..a45e76e4f 100644 --- a/src/unique_impl.rs +++ b/src/unique_impl.rs @@ -8,6 +8,7 @@ use std::fmt; /// /// See [`.unique_by()`](../trait.Itertools.html#method.unique) for more information. #[derive(Clone)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct UniqueBy { iter: I, // Use a hashmap for the entry API @@ -98,6 +99,7 @@ impl Iterator for Unique /// /// See [`.unique()`](../trait.Itertools.html#method.unique) for more information. #[derive(Clone)] +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Unique { iter: UniqueBy, } diff --git a/src/with_position.rs b/src/with_position.rs index 5086576a8..2a7c2b8ad 100644 --- a/src/with_position.rs +++ b/src/with_position.rs @@ -5,6 +5,7 @@ use std::iter::{Fuse,Peekable}; /// Iterator element type is `Position`. /// /// See [`.with_position()`](../trait.Itertools.html#method.with_position) for more information. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct WithPosition where I: Iterator, {