Re: [PATCH 7/9] rust: list: add cursor

From: Benno Lossin
Date: Thu Apr 04 2024 - 09:28:34 EST


On 03.04.24 14:49, Alice Ryhl wrote:
> On Wed, Apr 3, 2024 at 2:19 PM Benno Lossin <benno.lossin@xxxxxxxxx> wrote:
>> On 02.04.24 14:17, Alice Ryhl wrote:
>>> +impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> Cursor<'a, T, ID> {
>>> + /// Access the current element of this cursor.
>>> + pub fn current(&self) -> ArcBorrow<'_, T> {
>>> + // SAFETY: The `current` pointer points a value in the list.
>>> + let me = unsafe { T::view_value(ListLinks::from_fields(self.current)) };
>>> + // SAFETY:
>>> + // * All values in a list are stored in an `Arc`.
>>> + // * The value cannot be removed from the list for the duration of the lifetime annotated
>>> + // on the returned `ArcBorrow`, because removing it from the list would require mutable
>>> + // access to the cursor or the list. However, the `ArcBorrow` holds an immutable borrow
>>> + // on the cursor, which in turn holds an immutable borrow on the list, so any such
>>
>> The cursor has a mutable borrow on the list.
>>
>>
>>> + // mutable access requires first releasing the immutable borrow on the cursor.
>>> + // * Values in a list never have a `UniqueArc` reference.
>>
>> Is there some type invariant guaranteeing this?
>
> The List owns a ListArc reference to the value. It would be unsound
> for there to also be a UniqueArc reference to it.

I think it would be good to add the existence of the `ListArc` as an
explanation.

--
Cheers,
Benno