[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DACBRWLT0TOK.3BLVIST5ICH36@kernel.org>
Date: Mon, 02 Jun 2025 22:21:12 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Boqun Feng" <boqun.feng@...il.com>, "Alexandre Courbot"
<acourbot@...dia.com>
Cc: "Danilo Krummrich" <dakr@...nel.org>, "Miguel Ojeda" <ojeda@...nel.org>,
"Alex Gaynor" <alex.gaynor@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/4] rust: alloc: implement `Borrow` and `BorrowMut` for
`Vec`
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.
---
Cheers,
Benno
Powered by blists - more mailing lists