itertools
itertools copied to clipboard
unique_by used with a reference to Self::Item
Hi, I am trying to avoid cloning data while using unique_by and returning a reference to Self::Item, but there is an issue with the lifetimes. How can i do that?
use itertools::Itertools;
#[derive(Debug, PartialEq)]
struct Foo(pub String);
fn main() {
let data = vec![Foo("1".to_owned()), Foo("3".to_owned()), Foo("3".to_owned())];
itertools::assert_equal(data.into_iter().unique_by(|foo| &foo.0),
vec![Foo("1".to_owned()), Foo("3".to_owned())]);
}