polars_utils/reuse_vec.rs
1/// Re-uses the memory for a vec while clearing it. Allows casting the type of
2/// the vec at the same time. The stdlib specializes collect() to re-use the
3/// memory.
4pub fn reuse_vec<T, U>(v: Vec<T>) -> Vec<U> {
5 const {
6 assert!(core::mem::size_of::<T>() == core::mem::size_of::<U>());
7 assert!(core::mem::align_of::<T>() == core::mem::align_of::<U>());
8 }
9 v.into_iter().filter_map(|_| None).collect()
10}