All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Benno Lossin" <benno.lossin@proton.me>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] rust: alloc: allow coercion from `Box<T>` to `Box<dyn U>` if T implements U
Date: Fri, 11 Apr 2025 22:32:32 +0900	[thread overview]
Message-ID: <D93UIO9E7HBY.3USCKDO42JP5C@nvidia.com> (raw)
In-Reply-To: <D93TGVDQS6B6.1V6CKR5QSEWF6@proton.me>

On Fri Apr 11, 2025 at 9:43 PM JST, Benno Lossin wrote:
> On Fri Apr 11, 2025 at 2:07 PM CEST, Alexandre Courbot wrote:
>> This enables the creation of trait objects backed by a Box, similarly to
>> what can be done with the standard library.
>>
>> Suggested-by: Benno Lossin <benno.lossin@proton.me>
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>
> Reviewed-by: Benno Lossin <benno.lossin@proton.me>
>
>> ---
>> From this discussion on Zulip [1].
>>
>> Heavily inspired from the similar feature on `Arc`.
>>
>> [1] https://rust-for-linux.zulipchat.com/#narrow/channel/291565-Help/topic/Trait.20objects.3F/with/510689662
>> ---
>> Changes in v2:
>> - Use where clauses to improve readability.
>> - Fix build with rustc 1.78.
>> - Link to v1: https://lore.kernel.org/r/20250408-box_trait_objs-v1-1-58d8e78b0fb2@nvidia.com
>> ---
>>  rust/kernel/alloc/kbox.rs | 30 +++++++++++++++++++++++++++++-
>>  1 file changed, 29 insertions(+), 1 deletion(-)
>>
>> diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
>> index b77d32f3a58bab5ec73c612bdaaba0d79bfdff65..b9a905cd4bd285782b0db284b6771aec03e0c10b 100644
>> --- a/rust/kernel/alloc/kbox.rs
>> +++ b/rust/kernel/alloc/kbox.rs
>> @@ -32,6 +32,8 @@
>>  ///
>>  /// When dropping a [`Box`], the value is also dropped and the heap memory is automatically freed.
>>  ///
>> +/// [`Box`]es can also be used to store trait objects by coercing their type.
>> +///
>>  /// # Examples
>
> I agree with Miguel, you could move the added line above down here and
> also provide a simple example.

Oops, I completely forgot to address Miguel's comment, sorry about that.
Will send a new version.

  reply	other threads:[~2025-04-11 13:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-11 12:07 [PATCH v2] rust: alloc: allow coercion from `Box<T>` to `Box<dyn U>` if T implements U Alexandre Courbot
2025-04-11 12:24 ` Alice Ryhl
2025-04-11 12:43 ` Benno Lossin
2025-04-11 13:32   ` Alexandre Courbot [this message]
2025-04-11 13:10 ` Danilo Krummrich
2025-04-11 13:26   ` Alexandre Courbot
2025-04-11 14:22     ` Danilo Krummrich
2025-04-12  1:52       ` Alexandre Courbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D93UIO9E7HBY.3USCKDO42JP5C@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.