Re: [PATCH v3 0/4] rust: alloc: add Vec shrinking methods

From: Alice Ryhl

Date: Wed Feb 11 2026 - 01:51:54 EST


On Wed, Feb 11, 2026 at 2:08 AM Shivam Kalra <shivamkalra98@xxxxxxxxx> wrote:
>
> On 11/02/26 02:41, Danilo Krummrich wrote:
> > On Tue Feb 10, 2026 at 9:58 PM CET, Alice Ryhl wrote:
> >> On Tue, Feb 10, 2026 at 9:54 PM Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
> >> Yes that's what I meant. Only provide shrink_to() for those. After
> >> all, if Kmalloc never actually shrinks when you call realloc, what's
> >> the point of having KVec::shrink_to()?
> >
> > Nothing, but eventually we want a generic impl of shrink_to() with A::realloc().
> > But again, for now that's fine.
> Thanks for the discussion. Just want to confirm my understanding
> of the agreed approach:
>
> Since VVec and KVVec are type aliases for Vec<T, Vmalloc> and
> Vec<T, KVmalloc>, implementing shrink_to() on "only VVec and KVVec"
> means writing separate impl blocks:
>
> impl<T> Vec<T, Vmalloc> { fn shrink_to() { ... } }
> impl<T> Vec<T, KVmalloc> { fn shrink_to() { ... } }
>
> Is that what you had in mind, with the shrink logic duplicated
> in both? Or would you prefer a shared impl with a trait bound to
> avoid duplication?

I would prefer either a single stand-alone function that both impls
blocks call, or implementing it for KVmalloc only. Trait is overkill
here.

Alice