Skip to content

Commit ca31484

Browse files
bors[bot]zachs18
andauthored
Merge #686
686: Impl Clone for CircularTupleWindows r=jswrenn a=zachs18 Fixes #685 Co-authored-by: Zachary S <[email protected]>
2 parents 0b18d26 + 447370d commit ca31484

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/tuple_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<I, T> FusedIterator for TupleWindows<I, T>
201201
/// See [`.circular_tuple_windows()`](crate::Itertools::circular_tuple_windows) for more
202202
/// information.
203203
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
204-
#[derive(Debug)]
204+
#[derive(Debug, Clone)]
205205
pub struct CircularTupleWindows<I, T: Clone>
206206
where I: Iterator<Item = T::Item> + Clone,
207207
T: TupleCollect + Clone

tests/quick.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,71 @@ quickcheck! {
10211021
}
10221022
}
10231023

1024+
// tuple iterators
10241025
quickcheck! {
1026+
fn equal_circular_tuple_windows_1(a: Vec<u8>) -> bool {
1027+
let x = a.iter().map(|e| (e,) );
1028+
let y = a.iter().circular_tuple_windows::<(_,)>();
1029+
itertools::assert_equal(x,y);
1030+
true
1031+
}
1032+
1033+
fn equal_circular_tuple_windows_2(a: Vec<u8>) -> bool {
1034+
let x = (0..a.len()).map(|start_idx| (
1035+
&a[start_idx],
1036+
&a[(start_idx + 1) % a.len()],
1037+
));
1038+
let y = a.iter().circular_tuple_windows::<(_, _)>();
1039+
itertools::assert_equal(x,y);
1040+
true
1041+
}
1042+
1043+
fn equal_circular_tuple_windows_3(a: Vec<u8>) -> bool {
1044+
let x = (0..a.len()).map(|start_idx| (
1045+
&a[start_idx],
1046+
&a[(start_idx + 1) % a.len()],
1047+
&a[(start_idx + 2) % a.len()],
1048+
));
1049+
let y = a.iter().circular_tuple_windows::<(_, _, _)>();
1050+
itertools::assert_equal(x,y);
1051+
true
1052+
}
1053+
1054+
fn equal_circular_tuple_windows_4(a: Vec<u8>) -> bool {
1055+
let x = (0..a.len()).map(|start_idx| (
1056+
&a[start_idx],
1057+
&a[(start_idx + 1) % a.len()],
1058+
&a[(start_idx + 2) % a.len()],
1059+
&a[(start_idx + 3) % a.len()],
1060+
));
1061+
let y = a.iter().circular_tuple_windows::<(_, _, _, _)>();
1062+
itertools::assert_equal(x,y);
1063+
true
1064+
}
1065+
1066+
fn equal_cloned_circular_tuple_windows(a: Vec<u8>) -> bool {
1067+
let x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
1068+
let y = x.clone();
1069+
itertools::assert_equal(x,y);
1070+
true
1071+
}
1072+
1073+
fn equal_cloned_circular_tuple_windows_noninitial(a: Vec<u8>) -> bool {
1074+
let mut x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
1075+
let _ = x.next();
1076+
let y = x.clone();
1077+
itertools::assert_equal(x,y);
1078+
true
1079+
}
1080+
1081+
fn equal_cloned_circular_tuple_windows_complete(a: Vec<u8>) -> bool {
1082+
let mut x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
1083+
for _ in x.by_ref() {}
1084+
let y = x.clone();
1085+
itertools::assert_equal(x,y);
1086+
true
1087+
}
1088+
10251089
fn equal_tuple_windows_1(a: Vec<u8>) -> bool {
10261090
let x = a.windows(1).map(|s| (&s[0], ));
10271091
let y = a.iter().tuple_windows::<(_,)>();

0 commit comments

Comments
 (0)