Messages in this thread | | | From | "Andreas Hindborg (Samsung)" <> | Subject | Re: [PATCH v1] rust: add improved version of `ForeignOwnable::borrow_mut` | Date | Wed, 23 Aug 2023 18:09:15 +0200 |
| |
Alice Ryhl <aliceryhl@google.com> writes:
> Andreas Hindborg <nmi@metaspace.dk> writes: >>>> I am not sure this makes sense. How about splitting the trait in two, >>>> immutable and mutable and only implementing the immutable one or Arc? >>> >>> I used this design based on what would make sense for a linked list. The >>> idea is that we can have two different types of cursors for a linked >>> list: immutable and mutable. The immutable cursor lets you: >>> >>> * move around the linked list >>> * access the values using `borrow` >>> >>> The mutable cursor lets you: >>> >>> * move around the linked list >>> * delete or add items to the list >>> * access the values using `borrow_mut` >>> >>> The mutable cursor gives you extra abilities beyond the `borrow` vs >>> `borrow_mut` distinction, so we want to provide both types of cursors >>> even if the pointer type is Arc. To do that, we need a trait that >>> defines what it means to have mutable access to an Arc. >> >> I don't see how that prevents this trait from being split in two? > > Well, you could split the trait, but if you make the mutable iterator > require the `borrow_mut` trait, then you have to implement the mutable > trait for `Arc` too if you want the mutable iterator to work with `Arc`. > > And if you're always going to implement both traits, then maybe it > makes more sense to not split the traits?
Maybe. Do you have a prototype for the list cursor available?
BR Andreas
| |