Re: [PATCH 3/9] rust: list: add struct with prev/next pointers

From: Alice Ryhl
Date: Thu Apr 04 2024 - 10:03:59 EST


On Wed, Apr 3, 2024 at 5:57 PM Benno Lossin <benno.lossin@xxxxxxxxx> wrote:
>
> On 02.04.24 14:17, Alice Ryhl wrote:
> > +/// Implemented by types where a [`ListArc<Self>`] can be inserted into a `List`.
> > +///
> > +/// # Safety
> > +///
> > +/// Implementers must ensure that they provide the guarantees documented on the three methods
> > +/// below.
> > +///
> > +/// [`ListArc<Self>`]: ListArc
> > +pub unsafe trait ListItem<const ID: u64 = 0>: ListArcSafe<ID> {
> > + /// Views the [`ListLinks`] for this value.
> > + ///
> > + /// # Guarantees
> > + ///
> > + /// * If there is a currently active call to `prepare_to_insert`, then this returns the same
> > + /// pointer as the one returned by the currently active call to `prepare_to_insert`.
>
> I was a bit confused by the term "active call to `prepare_to_insert`",
> since I thought that the function would need to be executed at this
> moment. I inferred from below that you mean by this that there has been
> a `prepare_to_insert` call, but not yet a corresponding `post_remove`
> call.
> I did not yet find a better way to phrase this.
>
> I like putting the guarantees on the functions very much.

How about this?

If there is a previous call to `prepare_to_insert` and there is no
call to `post_remove` since the most recent such call, then this
returns the same pointer as the one returned by the most recent call
to `prepare_to_insert`.

Otherwise, the returned pointer points at a read-only [`ListLinks`]
with two null pointers.

Alice