diff --git a/vortex-vector/src/primitive/generic_mut_impl.rs b/vortex-vector/src/primitive/generic_mut_impl.rs index a201e51e425..1edb2816a65 100644 --- a/vortex-vector/src/primitive/generic_mut_impl.rs +++ b/vortex-vector/src/primitive/generic_mut_impl.rs @@ -3,6 +3,8 @@ //! Helper methods for [`PVectorMut`] that mimic the behavior of [`std::vec::Vec`]. +use std::mem::MaybeUninit; + use vortex_buffer::BufferMut; use vortex_dtype::NativePType; @@ -133,6 +135,22 @@ impl PVectorMut { } } } + + /// Returns the remaining spare capacity of the vector as a slice of [`MaybeUninit`]. + /// + /// The returned slice can be used to fill the buffer with data before marking the data as + /// initialized using unsafe methods like [`set_len`]. + /// + /// Note that this only provides access to the spare capacity of the **elements** buffer. + /// + /// After writing to the spare capacity and calling [`set_len`], the caller must also ensure the + /// validity mask is updated accordingly to maintain consistency. + /// + /// [`set_len`]: Self::set_len + #[inline] + pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit] { + self.elements.spare_capacity_mut() + } } #[cfg(test)]