Itertools::tuples, how to be sure there was no reminder?

There is the handy function tuples() in the itertools. But I cannot figure out how to find what was left after taking all possible tuples.
There is the method into_buffer(), that does exactly this, but I cannot find a way to use it in my situation.

use itertools::Itertools;

fn main() {
		
	let src_vec = vec![1,2,3,4,5];
	let tuple_vec = src_vec.iter().cloned().tuples::<(_,_,_)>().collect::<Vec<_>>();
	// want to be sure that there was nothing left behind
	println!("{:?}", tuple_vec);

	// what I've tried
	let tuples_iter = src_vec.iter().cloned().tuples::<(_,_,_)>();
	let tuple_vec = tuples_iter.collect::<Vec<_>>();
	
	//tuples_iter.into_buffer(); // Error: use of moved value: `tuples_iter`

	// want to be sure that there was nothing left behind
	println!("{:?}", tuple_vec);

	// I can use into_buffer, but that's not what I want
	let mut tuples_iter = src_vec.iter().cloned().tuples::<(_,_,_)>();
	while let Some(tuple) = tuples_iter.next() {
		println!("{:?}", tuple);
	}
	let reminder: Vec<_> = tuples_iter.into_buffer().collect_vec();
	println!("{:?}", reminder)
}

These sound contradictory. Do you want to use this method or not, after all?

Ok, you are right, I was not clear enough.
I want to collect tuples and then use into_buffer.

How about by_ref(), then.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.