diff --git a/.gitignore b/.gitignore index ca98cd96e..96ef6c0b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target/ +/target Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 1fc2da78e..54bb334f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "itertools" -version = "0.8.1" +version = "0.8.2" license = "MIT/Apache-2.0" repository = "https://github.com/bluss/rust-itertools" @@ -13,6 +13,9 @@ keywords = ["iterator", "data-structure", "zip", "product", "group-by"] categories = ["algorithms", "rust-patterns"] exclude = ["/bors.toml"] +[package.metadata.release] +no-dev-version = true + [lib] bench = false test = false @@ -36,6 +39,3 @@ use_std = [] [profile] bench = { debug = true } - -[package.metadata.release] -no-dev-version = true diff --git a/README.rst b/README.rst index 1792c7589..b06751afe 100644 --- a/README.rst +++ b/README.rst @@ -47,6 +47,9 @@ then it can't be accepted into ``libcore``, and you should propose it for ``iter Recent Changes -------------- +- 0.8.2 + + - Use :code:`slice::iter` instead of :code:`into_iter` to avoid future breakage (`#378 `_, by `@LukasKalbertodt `_) - 0.8.1 diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index c9b408cbd..0deaf6196 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -908,7 +908,7 @@ impl Iterator for WhileSome /// /// See [`.tuple_combinations()`](../trait.Itertools.html#method.tuple_combinations) for more /// information. -#[derive(Debug)] +#[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct TupleCombinations where I: Iterator, @@ -947,7 +947,7 @@ impl Iterator for TupleCombinations } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Tuple1Combination { iter: I, } @@ -972,7 +972,7 @@ impl HasCombination for (I::Item,) { macro_rules! impl_tuple_combination { ($C:ident $P:ident ; $A:ident, $($I:ident),* ; $($X:ident)*) => ( - #[derive(Debug)] + #[derive(Clone, Debug)] pub struct $C { item: Option, iter: I, @@ -1036,6 +1036,7 @@ impl_tuple_combination!(Tuple4Combination Tuple3Combination ; A, A, A, A, A; a b /// An iterator adapter to apply `Into` conversion to each element. /// /// See [`.map_into()`](../trait.Itertools.html#method.map_into) for more information. +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct MapInto { iter: I, @@ -1093,6 +1094,7 @@ where /// An iterator adapter to apply a transformation within a nested `Result`. /// /// See [`.map_results()`](../trait.Itertools.html#method.map_results) for more information. +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct MapResults { iter: I, @@ -1142,6 +1144,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. +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Positions { iter: I, @@ -1200,6 +1203,7 @@ impl DoubleEndedIterator for Positions /// An iterator adapter to apply a mutating function to each element before yielding it. /// /// See [`.update()`](../trait.Itertools.html#method.update) for more information. +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Update { iter: I, diff --git a/src/combinations.rs b/src/combinations.rs index 61833cecd..1c137d6e0 100644 --- a/src/combinations.rs +++ b/src/combinations.rs @@ -13,6 +13,20 @@ pub struct Combinations { first: bool, } +impl Clone for Combinations + where I: Clone + Iterator, + I::Item: Clone, +{ + fn clone(&self) -> Self { + Combinations { + k: self.k, + indices: self.indices.clone(), + pool: self.pool.clone(), + first: self.first, + } + } +} + impl fmt::Debug for Combinations where I: Iterator + fmt::Debug, I::Item: fmt::Debug, diff --git a/src/format.rs b/src/format.rs index c42806b01..72f2e5562 100644 --- a/src/format.rs +++ b/src/format.rs @@ -7,6 +7,7 @@ use std::cell::RefCell; /// exhausted. /// /// See [`.format_with()`](../trait.Itertools.html#method.format_with) for more information. +#[derive(Clone)] pub struct FormatWith<'a, I, F> { sep: &'a str, /// FormatWith uses interior mutability because Display::fmt takes &self. diff --git a/src/lib.rs b/src/lib.rs index d7c7960bb..70816d165 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -505,10 +505,11 @@ pub trait Itertools : Iterator { /// /// // Note: The `&` is significant here, `GroupBy` is iterable /// // only by reference. You can also call `.into_iter()` explicitly. + /// let mut data_grouped = Vec::new(); /// for (key, group) in &data.into_iter().group_by(|elt| *elt >= 0) { - /// // Check that the sum of each group is +/- 4. - /// assert_eq!(4, group.sum::().abs()); + /// data_grouped.push((key, group.collect())); /// } + /// assert_eq!(data_grouped, vec![(true, vec![1, 3]), (false, vec![-2, -2]), (true, vec![1, 0, 1, 2])]); /// ``` #[cfg(feature = "use_std")] fn group_by(self, key: F) -> GroupBy diff --git a/src/merge_join.rs b/src/merge_join.rs index e2bbc0a87..d941bb390 100644 --- a/src/merge_join.rs +++ b/src/merge_join.rs @@ -32,12 +32,11 @@ pub struct MergeJoinBy { } impl Clone for MergeJoinBy -where - I: Iterator, - J: Iterator, - PutBack>: Clone, - PutBack>: Clone, - F: Clone, + where I: Iterator, + J: Iterator, + PutBack>: Clone, + PutBack>: Clone, + F: Clone, { fn clone(&self) -> Self { MergeJoinBy { @@ -95,7 +94,7 @@ impl Iterator for MergeJoinBy let lower = ::std::cmp::max(a_lower, b_lower); let upper = match (a_upper, b_upper) { - (Some(x), Some(y)) => Some(x + y), + (Some(x), Some(y)) => x.checked_add(y), _ => None, }; diff --git a/src/permutations.rs b/src/permutations.rs index a9423375f..9d03c1063 100644 --- a/src/permutations.rs +++ b/src/permutations.rs @@ -14,7 +14,19 @@ pub struct Permutations { state: PermutationState, } -#[derive(Debug)] +impl Clone for Permutations + where I: Clone + Iterator, + I::Item: Clone, +{ + fn clone(&self) -> Self { + Permutations { + vals: self.vals.clone(), + state: self.state.clone(), + } + } +} + +#[derive(Clone, Debug)] enum PermutationState { StartUnknownLen { k: usize, @@ -27,7 +39,7 @@ enum PermutationState { Empty, } -#[derive(Debug)] +#[derive(Clone, Debug)] enum CompleteState { Start { n: usize, diff --git a/src/repeatn.rs b/src/repeatn.rs index 1c7c31001..f0a7bb7d9 100644 --- a/src/repeatn.rs +++ b/src/repeatn.rs @@ -3,7 +3,7 @@ /// /// See [`repeat_n()`](../fn.repeat_n.html) for more information. #[must_use = "iterators are lazy and do nothing unless consumed"] -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct RepeatN { elt: Option, n: usize, diff --git a/src/sources.rs b/src/sources.rs index a579f3d9c..c3f0110f2 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -6,6 +6,7 @@ use std::fmt; use std::mem; /// See [`repeat_call`](../fn.repeat_call.html) for more information. +#[derive(Clone)] #[deprecated(note="Use std repeat_with() instead", since="0.8")] pub struct RepeatCall { f: F, diff --git a/src/tuple_impl.rs b/src/tuple_impl.rs index 0daa7800c..d99145d8e 100644 --- a/src/tuple_impl.rs +++ b/src/tuple_impl.rs @@ -6,7 +6,7 @@ use std::iter::Fuse; /// /// See [`.tuples()`](../trait.Itertools.html#method.tuples) and /// [`Tuples::into_buffer()`](struct.Tuples.html#method.into_buffer). -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct TupleBuffer where T: TupleCollect { @@ -61,6 +61,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. +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Tuples where I: Iterator, @@ -117,7 +118,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"] -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct TupleWindows where I: Iterator, T: TupleCollect diff --git a/src/with_position.rs b/src/with_position.rs index 2a7c2b8ad..8e39cb700 100644 --- a/src/with_position.rs +++ b/src/with_position.rs @@ -13,6 +13,18 @@ pub struct WithPosition peekable: Peekable>, } +impl Clone for WithPosition + where I: Clone + Iterator, + I::Item: Clone, +{ + fn clone(&self) -> Self { + WithPosition { + handled_first: self.handled_first, + peekable: self.peekable.clone(), + } + } +} + /// Create a new `WithPosition` iterator. pub fn with_position(iter: I) -> WithPosition where I: Iterator,