Re: [PATCH 2/2] rust: alloc: add `Vec::dec_len`
From: Alice Ryhl
Date: Mon Mar 17 2025 - 07:48:03 EST
On Mon, Mar 17, 2025 at 07:34:44AM -0400, Tamir Duberstein wrote:
> On Mon, Mar 17, 2025 at 6:04 AM Benno Lossin <benno.lossin@xxxxxxxxx> wrote:
> >
> > On Sun Mar 16, 2025 at 11:32 PM CET, Tamir Duberstein wrote:
> > > Add `Vec::dec_len` that reduces the length of the receiver. This method
> > > is intended to be used from methods that remove elements from `Vec` such
> > > as `truncate`, `pop`, `remove`, and others. This method is intentionally
> > > not `pub`.
> >
> > I think it should be `pub`. Otherwise we're loosing functionality
> > compared to now. If one decides to give the raw pointer to some C API
> > that takes ownership of the pointer, then I want them to be able to call
> > `dec_len` manually.
>
> This is premature. It is trivial to make this function pub when the need arises.
Normally I'd agree with Benno, but in this case I think having it
private is preferable. The function is safe, so it's too easy for
end-users to confuse it with truncate.
Alice