rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Benno Lossin <lossin@kernel.org>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@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>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`
Date: Mon, 2 Jun 2025 13:45:15 -0700	[thread overview]
Message-ID: <aD4NW2vDc9rKBDPy@tardis.local> (raw)
In-Reply-To: <DACBRWLT0TOK.3BLVIST5ICH36@kernel.org>

On Mon, Jun 02, 2025 at 10:21:12PM +0200, Benno Lossin wrote:
> On Mon Jun 2, 2025 at 5:06 PM CEST, Boqun Feng wrote:
> > On Mon, Jun 02, 2025 at 10:13:22AM +0900, Alexandre Courbot wrote:
> >> On Mon Jun 2, 2025 at 1:11 AM JST, Benno Lossin wrote:
> >> > On Sun Jun 1, 2025 at 5:00 AM CEST, Alexandre Courbot wrote:
> >> >> Implement these two common traits, which allow generic types to store
> >> >> either an owned value or a reference to it.
> >> >
> >> > I don't understand the second part of the sentence.
> >> 
> >> I want to say that Borrow allows you to do something like:
> >> 
> >>     struct Foo<B: Borrow<u32>>(B);
> >> 
> >>     // `foo1` owns its value...
> >>     let foo1 = Foo(0x12);
> >> 
> >>     let i = 0x24;
> >>     // ... but `foo2` just borrows it, subject to the lifetime of `i`.
> >>     let foo2 = Foo(&i);
> >> 
> >> And the implementations in this series also let you do:
> >> 
> >>     // `foo3`'s value is owned, but heap-allocated
> >>     let foo3 = Arc::new(KBox::new(0x56, GFP_KERNEL)?);
> >> 
> >>     let j = Arc::new(0x78, GFP_KERNEL)?;
> >>     // `foo4`'s value is shared and its lifetime runtime-managed.
> >>     let foo4 = Foo(j.clone());
> >
> > Maybe you could put these in the "# Examples" section before impl
> > blocks. E.g
> >
> > 	/// # Examples
> > 	/// ```
> > 	/// <you case above>
> > 	/// ```
> > 	impl<T, A> Borrow<[T]> for Vec<T, A> ...
> 
> Does that get rendered in the docs? If not, I don't think we should do
> it.

It does. I just tried myself, in the "Trait Implementations" section,
if you provide a doc comment for an impl block, it will show under the
"impl line" of corresponding to that impl block, including ```code```.

Regards,
Boqun

> 
> ---
> Cheers,
> Benno

  reply	other threads:[~2025-06-02 20:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-01  3:00 [PATCH 0/4] rust: a few common Borrow/BorrowMut implementations Alexandre Courbot
2025-06-01  3:00 ` [PATCH 1/4] rust: alloc: implement `Borrow` and `BorrowMut` for `Vec` Alexandre Courbot
2025-06-01 16:11   ` Benno Lossin
2025-06-02  1:13     ` Alexandre Courbot
2025-06-02 15:06       ` Boqun Feng
2025-06-02 20:21         ` Benno Lossin
2025-06-02 20:45           ` Boqun Feng [this message]
2025-06-13  6:15         ` Alexandre Courbot
2025-06-04  7:34       ` Benno Lossin
2025-06-13  5:35         ` Alexandre Courbot
2025-06-13  7:45           ` Benno Lossin
2025-06-01  3:00 ` [PATCH 2/4] rust: alloc: implement `Borrow` and `BorrowMut` for `Arc` types Alexandre Courbot
2025-06-01  3:06   ` Alexandre Courbot
2025-06-01 16:17   ` Benno Lossin
2025-06-01  3:00 ` [PATCH 3/4] rust: alloc: implement `Borrow` and `BorrowMut` for `KBox` Alexandre Courbot
2025-06-01  3:00 ` [PATCH 4/4] rust: alloc: implement `Borrow` and `BorrowMut` for `CString` Alexandre Courbot
2025-06-02  8:49 ` [PATCH 0/4] rust: a few common Borrow/BorrowMut implementations Alice Ryhl

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=aD4NW2vDc9rKBDPy@tardis.local \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).