Re: [PATCH v4 1/4] rust: iov: add iov_iter abstractions for ITER_SOURCE
From: Danilo Krummrich
Date: Wed Aug 13 2025 - 07:27:57 EST
On Wed Aug 13, 2025 at 10:27 AM CEST, Alice Ryhl wrote:
> + /// Read data from this IO vector and append it to a vector.
> + ///
> + /// Returns the number of bytes that have been copied.
> + #[inline]
> + pub fn copy_from_iter_vec<A: Allocator>(
> + &mut self,
> + out: &mut Vec<u8, A>,
> + flags: Flags,
> + ) -> Result<usize> {
> + out.reserve(self.len(), flags)?;
> + let len = self.copy_from_iter_raw(out.spare_capacity_mut()).len();
> + // SAFETY: `Self::copy_from_iter_raw` guarantees that the first `len` bytes of the spare
> + // capacity have been initialized.
Technically, this covers the safety requirements from inc_len(). However, do we
want to provide a list of justifications if the unsafe functions has a list of
requirements, such that they are easier to match?
> + unsafe { out.inc_len(len) };
> + Ok(len)
> + }
Either way,
Reviewed-by: Danilo Krummrich <dakr@xxxxxxxxxx>