Skip to content

Commit 1e97bf2

Browse files
committed
Add derive(Clone) where possible
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 09403b3 commit 1e97bf2

File tree

9 files changed

+69
-8
lines changed

9 files changed

+69
-8
lines changed

src/adaptors/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ impl<I, A> Iterator for WhileSome<I>
886886
///
887887
/// See [`.tuple_combinations()`](../trait.Itertools.html#method.tuple_combinations) for more
888888
/// information.
889-
#[derive(Debug)]
889+
#[derive(Clone, Debug)]
890890
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
891891
pub struct TupleCombinations<I, T>
892892
where I: Iterator,
@@ -925,7 +925,7 @@ impl<I, T> Iterator for TupleCombinations<I, T>
925925
}
926926
}
927927

928-
#[derive(Debug)]
928+
#[derive(Clone, Debug)]
929929
pub struct Tuple1Combination<I> {
930930
iter: I,
931931
}
@@ -950,7 +950,7 @@ impl<I: Iterator> HasCombination<I> for (I::Item,) {
950950

951951
macro_rules! impl_tuple_combination {
952952
($C:ident $P:ident ; $A:ident, $($I:ident),* ; $($X:ident)*) => (
953-
#[derive(Debug)]
953+
#[derive(Clone, Debug)]
954954
pub struct $C<I: Iterator> {
955955
item: Option<I::Item>,
956956
iter: I,
@@ -1014,6 +1014,7 @@ impl_tuple_combination!(Tuple4Combination Tuple3Combination ; A, A, A, A, A; a b
10141014
/// An iterator adapter to apply `Into` conversion to each element.
10151015
///
10161016
/// See [`.map_into()`](../trait.Itertools.html#method.map_into) for more information.
1017+
#[derive(Clone)]
10171018
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
10181019
pub struct MapInto<I, R> {
10191020
iter: I,
@@ -1071,6 +1072,7 @@ where
10711072
/// An iterator adapter to apply a transformation within a nested `Result`.
10721073
///
10731074
/// See [`.map_results()`](../trait.Itertools.html#method.map_results) for more information.
1075+
#[derive(Clone)]
10741076
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
10751077
pub struct MapResults<I, F> {
10761078
iter: I,
@@ -1120,6 +1122,7 @@ impl<I, F, T, U, E> Iterator for MapResults<I, F>
11201122
/// An iterator adapter to get the positions of each element that matches a predicate.
11211123
///
11221124
/// See [`.positions()`](../trait.Itertools.html#method.positions) for more information.
1125+
#[derive(Clone)]
11231126
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
11241127
pub struct Positions<I, F> {
11251128
iter: I,
@@ -1178,6 +1181,7 @@ impl<I, F> DoubleEndedIterator for Positions<I, F>
11781181
/// An iterator adapter to apply a mutating function to each element before yielding it.
11791182
///
11801183
/// See [`.update()`](../trait.Itertools.html#method.update) for more information.
1184+
#[derive(Clone)]
11811185
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
11821186
pub struct Update<I, F> {
11831187
iter: I,

src/combinations.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ pub struct Combinations<I: Iterator> {
1313
first: bool,
1414
}
1515

16+
impl<I> Clone for Combinations<I>
17+
where I: Clone + Iterator,
18+
I::Item: Clone,
19+
{
20+
fn clone(&self) -> Self {
21+
Combinations {
22+
k: self.k,
23+
indices: self.indices.clone(),
24+
pool: self.pool.clone(),
25+
first: self.first,
26+
}
27+
}
28+
}
29+
1630
impl<I> fmt::Debug for Combinations<I>
1731
where I: Iterator + fmt::Debug,
1832
I::Item: fmt::Debug,

src/format.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::cell::RefCell;
77
/// exhausted.
88
///
99
/// See [`.format_with()`](../trait.Itertools.html#method.format_with) for more information.
10+
#[derive(Clone)]
1011
pub struct FormatWith<'a, I, F> {
1112
sep: &'a str,
1213
/// FormatWith uses interior mutability because Display::fmt takes &self.

src/merge_join.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ pub struct MergeJoinBy<I: Iterator, J: Iterator, F> {
3131
cmp_fn: F
3232
}
3333

34+
impl<I, J, F> Clone for MergeJoinBy<I, J, F>
35+
where I: Clone + Iterator,
36+
I::Item: Clone,
37+
J: Clone + Iterator,
38+
J::Item: Clone,
39+
F: Clone,
40+
{
41+
fn clone(&self) -> Self {
42+
MergeJoinBy {
43+
left: self.left.clone(),
44+
right: self.right.clone(),
45+
cmp_fn: self.cmp_fn.clone(),
46+
}
47+
}
48+
}
49+
3450
impl<I, J, F> fmt::Debug for MergeJoinBy<I, J, F>
3551
where I: Iterator + fmt::Debug,
3652
I::Item: fmt::Debug,

src/permutations.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ pub struct Permutations<I: Iterator> {
1414
state: PermutationState,
1515
}
1616

17-
#[derive(Debug)]
17+
impl<I> Clone for Permutations<I>
18+
where I: Clone + Iterator,
19+
I::Item: Clone,
20+
{
21+
fn clone(&self) -> Self {
22+
Permutations {
23+
vals: self.vals.clone(),
24+
state: self.state.clone(),
25+
}
26+
}
27+
}
28+
29+
#[derive(Clone, Debug)]
1830
enum PermutationState {
1931
StartUnknownLen {
2032
k: usize,
@@ -27,7 +39,7 @@ enum PermutationState {
2739
Empty,
2840
}
2941

30-
#[derive(Debug)]
42+
#[derive(Clone, Debug)]
3143
enum CompleteState {
3244
Start {
3345
n: usize,

src/repeatn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
///
44
/// See [`repeat_n()`](../fn.repeat_n.html) for more information.
55
#[must_use = "iterators are lazy and do nothing unless consumed"]
6-
#[derive(Debug)]
6+
#[derive(Clone, Debug)]
77
pub struct RepeatN<A> {
88
elt: Option<A>,
99
n: usize,

src/sources.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::fmt;
66
use std::mem;
77

88
/// See [`repeat_call`](../fn.repeat_call.html) for more information.
9+
#[derive(Clone)]
910
#[deprecated(note="Use std repeat_with() instead", since="0.8")]
1011
pub struct RepeatCall<F> {
1112
f: F,

src/tuple_impl.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::iter::Fuse;
66
///
77
/// See [`.tuples()`](../trait.Itertools.html#method.tuples) and
88
/// [`Tuples::into_buffer()`](struct.Tuples.html#method.into_buffer).
9-
#[derive(Debug)]
9+
#[derive(Clone, Debug)]
1010
pub struct TupleBuffer<T>
1111
where T: TupleCollect
1212
{
@@ -61,6 +61,7 @@ impl<T> ExactSizeIterator for TupleBuffer<T>
6161
/// An iterator that groups the items in tuples of a specific size.
6262
///
6363
/// See [`.tuples()`](../trait.Itertools.html#method.tuples) for more information.
64+
#[derive(Clone)]
6465
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
6566
pub struct Tuples<I, T>
6667
where I: Iterator<Item = T::Item>,
@@ -117,7 +118,7 @@ impl<I, T> Tuples<I, T>
117118
/// See [`.tuple_windows()`](../trait.Itertools.html#method.tuple_windows) for more
118119
/// information.
119120
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
120-
#[derive(Debug)]
121+
#[derive(Clone, Debug)]
121122
pub struct TupleWindows<I, T>
122123
where I: Iterator<Item = T::Item>,
123124
T: TupleCollect

src/with_position.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ pub struct WithPosition<I>
1313
peekable: Peekable<Fuse<I>>,
1414
}
1515

16+
impl<I> Clone for WithPosition<I>
17+
where I: Clone + Iterator,
18+
I::Item: Clone,
19+
{
20+
fn clone(&self) -> Self {
21+
WithPosition {
22+
handled_first: self.handled_first,
23+
peekable: self.peekable.clone(),
24+
}
25+
}
26+
}
27+
1628
/// Create a new `WithPosition` iterator.
1729
pub fn with_position<I>(iter: I) -> WithPosition<I>
1830
where I: Iterator,

0 commit comments

Comments
 (0)