Skip to main content

polars_utils/
scratch_vec.rs

1/// Vec container with a getter that clears the vec.
2#[derive(Default)]
3pub struct ScratchVec<T>(Vec<T>);
4
5impl<T> ScratchVec<T> {
6    pub fn with_capacity(capacity: usize) -> Self {
7        Self(Vec::with_capacity(capacity))
8    }
9
10    /// Clear the vec and return a mutable reference to it.
11    pub fn get(&mut self) -> &mut Vec<T> {
12        self.0.clear();
13        &mut self.0
14    }
15}