Re: [PATCH v4 1/2] rust: add basic Pin<Vec<T, A>> abstractions
From: Benno Lossin
Date: Sun Oct 12 2025 - 12:27:00 EST
On Sun Oct 12, 2025 at 4:52 PM CEST, Markus Probst wrote:
> @@ -109,6 +111,21 @@ pub struct Vec<T, A: Allocator> {
> _p: PhantomData<A>,
> }
>
> +/// Extension for Pin<Vec<T, A>>
> +pub trait PinnedVecExt<T> {
Why is this an extension trait? Couldn't we directly implement this on
`Vec<T>` with `self: Pin<&mut Self>`?
---
Cheers,
Benno
> + /// Pin-initializes P and appends it to the back of the [`Vec`] instance without reallocating.
> + fn push_pin_init<E: From<PushError<P>>, P: PinInit<T, E>>(&mut self, init: P) -> Result<(), E>;
> +
> + /// Shortens the vector, setting the length to `len` and drops the removed values.
> + /// If `len` is greater than or equal to the current length, this does nothing.
> + ///
> + /// This has no effect on the capacity and will not allocate.
> + fn truncate(&mut self, len: usize);
> +
> + /// Removes the last element from a vector and drops it returning true, or false if it is empty.
> + fn pop(&mut self) -> bool;
> +}
> +
> /// Type alias for [`Vec`] with a [`Kmalloc`] allocator.
> ///
> /// # Examples