lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DAL5THET602V.345BOV2PJGATF@nvidia.com>
Date: Fri, 13 Jun 2025 14:35:09 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Benno Lossin" <lossin@...nel.org>, "Danilo Krummrich"
 <dakr@...nel.org>, "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>, "Andreas Hindborg" <a.hindborg@...nel.org>,
 "Alice Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>
Cc: <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 Wed Jun 4, 2025 at 4:34 PM JST, Benno Lossin wrote:
> On Mon Jun 2, 2025 at 3:13 AM CEST, Alexandre Courbot wrote:
>> Hi Benno,
>>
>> 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());
>
> How about something like:
>
>     Implement `Borrow<[T]>` and `BorrowMut<[T]>` for `Vec<T>`. This allows
>     `Vec<T>` to be used in generic APIs asking for types implementing those
>     traits. `[T; N]` and `&mut [T]` also implement those traits allowing
>     users to use either owned, borrowed and heap-owned values.

This is super clear, and I think I'll just reuse this message as-is if
that's ok with you. Thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ