From 97c6265e15b2c712b336de901b8f483935d24460 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 15 Oct 2019 21:02:20 +0200 Subject: [PATCH 1/6] Clarify documentation for group_by --- src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 From 1e97bf25b59db7bf9b53eaf8ca33bd92744eed1f Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 9 Nov 2019 18:13:51 -0800 Subject: [PATCH 2/6] Add derive(Clone) where possible Signed-off-by: Anders Kaseorg --- src/adaptors/mod.rs | 10 +++++++--- src/combinations.rs | 14 ++++++++++++++ src/format.rs | 1 + src/merge_join.rs | 16 ++++++++++++++++ src/permutations.rs | 16 ++++++++++++++-- src/repeatn.rs | 2 +- src/sources.rs | 1 + src/tuple_impl.rs | 5 +++-- src/with_position.rs | 12 ++++++++++++ 9 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index 4d0f5e129..2531d34de 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -886,7 +886,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, @@ -925,7 +925,7 @@ impl Iterator for TupleCombinations } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Tuple1Combination { iter: I, } @@ -950,7 +950,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, @@ -1014,6 +1014,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, @@ -1071,6 +1072,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, @@ -1120,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. +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct Positions { iter: I, @@ -1178,6 +1181,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/merge_join.rs b/src/merge_join.rs index 5f9a0f401..fcd762667 100644 --- a/src/merge_join.rs +++ b/src/merge_join.rs @@ -31,6 +31,22 @@ pub struct MergeJoinBy { cmp_fn: F } +impl Clone for MergeJoinBy + where I: Clone + Iterator, + I::Item: Clone, + J: Clone + Iterator, + J::Item: Clone, + F: Clone, +{ + fn clone(&self) -> Self { + MergeJoinBy { + left: self.left.clone(), + right: self.right.clone(), + cmp_fn: self.cmp_fn.clone(), + } + } +} + impl fmt::Debug for MergeJoinBy where I: Iterator + fmt::Debug, I::Item: fmt::Debug, 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, From 687e14510a9b6606580e5ada953e04f90c9f7de8 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Sat, 23 Nov 2019 11:12:49 -0500 Subject: [PATCH 3/6] 0.8.2 Changelog --- README.rst | 3 +++ 1 file changed, 3 insertions(+) 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 From dd7fd96b3246f607825420f12141ebd1e0c4185a Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Sat, 23 Nov 2019 11:24:17 -0500 Subject: [PATCH 4/6] (cargo-release) version 0.8.2 --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From 9f41c18435249691cb06c0e98ca5653a3d02ed57 Mon Sep 17 00:00:00 2001 From: Andrew Hickman Date: Sat, 23 Nov 2019 18:06:38 +0000 Subject: [PATCH 5/6] Fix potential overflow in MergeJoinBy::size_hint --- src/merge_join.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/merge_join.rs b/src/merge_join.rs index 5f9a0f401..8e2b93042 100644 --- a/src/merge_join.rs +++ b/src/merge_join.rs @@ -78,7 +78,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, }; From 3c48fcf1701cf615131ecefb5ca5ac57ca87c548 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 1 Oct 2019 19:24:17 -0400 Subject: [PATCH 6/6] gitignore: ignore target as a symlink --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ca98cd96e..96ef6c0b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target/ +/target Cargo.lock