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,