Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into merge_join_by_mis…
Browse files Browse the repository at this point in the history
…sing_specializations

# Conflicts:
#	src/merge_join.rs
  • Loading branch information
Ten0 committed Jan 1, 2020
2 parents a0eb01c + 505e0f4 commit 8bae261
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@
/target/
/target
Cargo.lock
8 changes: 4 additions & 4 deletions 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"
Expand All @@ -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
Expand All @@ -36,6 +39,3 @@ use_std = []

[profile]
bench = { debug = true }

[package.metadata.release]
no-dev-version = true
3 changes: 3 additions & 0 deletions README.rst
Expand Up @@ -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 <https://github.com/rust-itertools/itertools/pull/378>`_, by `@LukasKalbertodt <https://github.com/LukasKalbertodt>`_)

- 0.8.1

Expand Down
10 changes: 7 additions & 3 deletions src/adaptors/mod.rs
Expand Up @@ -908,7 +908,7 @@ impl<I, A> Iterator for WhileSome<I>
///
/// 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<I, T>
where I: Iterator,
Expand Down Expand Up @@ -947,7 +947,7 @@ impl<I, T> Iterator for TupleCombinations<I, T>
}
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct Tuple1Combination<I> {
iter: I,
}
Expand All @@ -972,7 +972,7 @@ impl<I: Iterator> HasCombination<I> 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<I: Iterator> {
item: Option<I::Item>,
iter: I,
Expand Down Expand Up @@ -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<I, R> {
iter: I,
Expand Down Expand Up @@ -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<I, F> {
iter: I,
Expand Down Expand Up @@ -1142,6 +1144,7 @@ impl<I, F, T, U, E> Iterator for MapResults<I, F>
/// 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<I, F> {
iter: I,
Expand Down Expand Up @@ -1200,6 +1203,7 @@ impl<I, F> DoubleEndedIterator for Positions<I, F>
/// 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<I, F> {
iter: I,
Expand Down
14 changes: 14 additions & 0 deletions src/combinations.rs
Expand Up @@ -13,6 +13,20 @@ pub struct Combinations<I: Iterator> {
first: bool,
}

impl<I> Clone for Combinations<I>
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<I> fmt::Debug for Combinations<I>
where I: Iterator + fmt::Debug,
I::Item: fmt::Debug,
Expand Down
1 change: 1 addition & 0 deletions src/format.rs
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Expand Up @@ -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::<i32>().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<K, F>(self, key: F) -> GroupBy<K, Self, F>
Expand Down
13 changes: 6 additions & 7 deletions src/merge_join.rs
Expand Up @@ -32,12 +32,11 @@ pub struct MergeJoinBy<I: Iterator, J: Iterator, F> {
}

impl<I, J, F> Clone for MergeJoinBy<I, J, F>
where
I: Iterator,
J: Iterator,
PutBack<Fuse<I>>: Clone,
PutBack<Fuse<J>>: Clone,
F: Clone,
where I: Iterator,
J: Iterator,
PutBack<Fuse<I>>: Clone,
PutBack<Fuse<J>>: Clone,
F: Clone,
{
fn clone(&self) -> Self {
MergeJoinBy {
Expand Down Expand Up @@ -95,7 +94,7 @@ impl<I, J, F> Iterator for MergeJoinBy<I, J, F>
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,
};

Expand Down
16 changes: 14 additions & 2 deletions src/permutations.rs
Expand Up @@ -14,7 +14,19 @@ pub struct Permutations<I: Iterator> {
state: PermutationState,
}

#[derive(Debug)]
impl<I> Clone for Permutations<I>
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,
Expand All @@ -27,7 +39,7 @@ enum PermutationState {
Empty,
}

#[derive(Debug)]
#[derive(Clone, Debug)]
enum CompleteState {
Start {
n: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/repeatn.rs
Expand Up @@ -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<A> {
elt: Option<A>,
n: usize,
Expand Down
1 change: 1 addition & 0 deletions src/sources.rs
Expand Up @@ -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: F,
Expand Down
5 changes: 3 additions & 2 deletions src/tuple_impl.rs
Expand Up @@ -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<T>
where T: TupleCollect
{
Expand Down Expand Up @@ -61,6 +61,7 @@ impl<T> ExactSizeIterator for TupleBuffer<T>
/// 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<I, T>
where I: Iterator<Item = T::Item>,
Expand Down Expand Up @@ -117,7 +118,7 @@ impl<I, T> Tuples<I, T>
/// 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<I, T>
where I: Iterator<Item = T::Item>,
T: TupleCollect
Expand Down
12 changes: 12 additions & 0 deletions src/with_position.rs
Expand Up @@ -13,6 +13,18 @@ pub struct WithPosition<I>
peekable: Peekable<Fuse<I>>,
}

impl<I> Clone for WithPosition<I>
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<I>(iter: I) -> WithPosition<I>
where I: Iterator,
Expand Down

0 comments on commit 8bae261

Please sign in to comment.