Skip to content

Commit

Permalink
Merge #382
Browse files Browse the repository at this point in the history
382: Add derive(Clone) where possible r=jswrenn a=andersk



Co-authored-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
bors[bot] and andersk committed Jan 1, 2020
2 parents 775274c + 1e97bf2 commit 505e0f4
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/adaptors/mod.rs
Expand Up @@ -886,7 +886,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 @@ -925,7 +925,7 @@ impl<I, T> Iterator for TupleCombinations<I, T>
}
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct Tuple1Combination<I> {
iter: I,
}
Expand All @@ -950,7 +950,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 @@ -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<I, R> {
iter: I,
Expand Down Expand Up @@ -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<I, F> {
iter: I,
Expand Down Expand Up @@ -1120,6 +1122,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 @@ -1178,6 +1181,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
16 changes: 16 additions & 0 deletions src/merge_join.rs
Expand Up @@ -31,6 +31,22 @@ pub struct MergeJoinBy<I: Iterator, J: Iterator, F> {
cmp_fn: F
}

impl<I, J, F> Clone for MergeJoinBy<I, J, F>
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<I, J, F> fmt::Debug for MergeJoinBy<I, J, F>
where I: Iterator + fmt::Debug,
I::Item: fmt::Debug,
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 505e0f4

Please sign in to comment.