[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ-ks9mHp=uZUq0BN6D33+s-eEO1vN+1a4_mZahuqLD9-A1UeQ@mail.gmail.com>
Date: Thu, 31 Oct 2024 08:23:11 -0400
From: Tamir Duberstein <tamird@...il.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, Martin Rodriguez Reboredo <yakoyoku@...il.com>
Subject: Re: [PATCH 5/5] rust: add improved version of `ForeignOwnable::borrow_mut`
On Thu, Oct 31, 2024 at 6:54 AM Alice Ryhl <aliceryhl@...gle.com> wrote:
>
> On Wed, Oct 30, 2024 at 9:46 PM Tamir Duberstein <tamird@...il.com> wrote:
> >
> > From: Alice Ryhl <aliceryhl@...gle.com>
> >
> > Previously, the `ForeignOwnable` trait had a method called `borrow_mut`
> > that was intended to provide mutable access to the inner value. However,
> > the method accidentally made it possible to change the address of the
> > object being modified, which usually isn't what we want. (And when we
> > want that, it can be done by calling `from_foreign` and `into_foreign`,
> > like how the old `borrow_mut` was implemented.)
> >
> > In this patch, we introduce an alternate definition of `borrow_mut` that
> > solves the previous problem. Conceptually, given a pointer type `P` that
> > implements `ForeignOwnable`, the `borrow_mut` method gives you the same
> > kind of access as an `&mut P` would, except that it does not let you
> > change the pointer `P` itself.
> >
> > This is analogous to how the existing `borrow` method provides the same
> > kind of access to the inner value as an `&P`.
> >
> > Note that for types like `Arc`, having an `&mut Arc<T>` only gives you
> > immutable access to the inner `T`. This is because mutable references
> > assume exclusive access, but there might be other handles to the same
> > reference counted value, so the access isn't exclusive. The `Arc` type
> > implements this by making `borrow_mut` return the same type as `borrow`.
> >
> > Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
> > Reviewed-by: Boqun Feng <boqun.feng@...il.com>
> > Reviewed-by: Benno Lossin <benno.lossin@...ton.me>
> > Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@...il.com>
>
> You must add your own SoB at the end when resending other's patches.
>
> Alice
Thanks, I'll add it in v2. Does the order matter?
Powered by blists - more mailing lists