evobench_tools/utillib/recycle.rs
1use std::collections::BTreeSet;
2
3pub trait RecycleVec {
4 /// Recycle the storage of `self` by returning a new Vec that
5 /// reuses it.
6 fn recycle_vec<U>(self) -> Vec<U>;
7}
8
9impl<T> RecycleVec for Vec<T> {
10 #[inline]
11 fn recycle_vec<U>(mut self) -> Vec<U> {
12 self.clear();
13 self.into_iter().map(|_| unreachable!()).collect()
14 }
15}
16
17// Does this work, too?
18impl<T> RecycleVec for BTreeSet<T> {
19 #[inline]
20 fn recycle_vec<U>(mut self) -> Vec<U> {
21 self.clear();
22 self.into_iter().map(|_| unreachable!()).collect()
23 }
24}