Skip to content

Commit

Permalink
Add Clone trait to Unique
Browse files Browse the repository at this point in the history
Using a Unique iterator requires the Clone trait, so
require this trait when creating the Unique object.
  • Loading branch information
gilhooleyd authored and Philippe-Cholet committed Oct 6, 2023
1 parent 4d2bd4e commit a70646a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/unique_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ where
pub fn unique<I>(iter: I) -> Unique<I>
where
I: Iterator,
I::Item: Eq + Hash,
I::Item: Eq + Hash + Clone,
{
Unique {
iter: UniqueBy {
Expand Down
16 changes: 16 additions & 0 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ use rand::{
use rand::{seq::SliceRandom, thread_rng};
use std::{cmp::min, fmt::Debug, marker::PhantomData};

#[test]
fn unique_iterator() {
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
struct Item {
value: u32,
}
impl Item {
fn new(value: u32) -> Item {
Item {value}
}
}
let data = std::vec![Item::new(1), Item::new(2), Item::new(3), Item::new(2)];
let data: Vec<_> = data.into_iter().unique().collect();
assert_eq!(data, std::vec![Item::new(1), Item::new(2), Item::new(3)]);
}

#[test]
fn product3() {
let prod = iproduct!(0..3, 0..2, 0..2);
Expand Down

0 comments on commit a70646a

Please sign in to comment.