[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250601-borrow_impls-v1-0-e1caeb428db4@nvidia.com>
Date: Sun, 01 Jun 2025 12:00:38 +0900
From: Alexandre Courbot <acourbot@...dia.com>
To: 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>,
Benno Lossin <lossin@...nel.org>, 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,
Alexandre Courbot <acourbot@...dia.com>
Subject: [PATCH 0/4] rust: a few common Borrow/BorrowMut implementations
The Borrow trait has multiple uses, one of them being to store either an
owned value or a reference to it inside a generic container. This series
adds these implementations for `Box`, `Arc`, `Vec`, and `CString`. I
came across the need for this while experimenting with the scatterlist
abstraction series [1].
This series provides just the `Borrow` and `BorrowMut` implementations,
but another common use of `Borrow` in the standard library is to use the
borrowed type for key lookups in collections. For this to work, a few
consistency traits (`Eq`, `Hash`, and `Ord`) need to be implemented. I
am not sure whether we want this on kernel types as well, but please let
me know if we do and I will add them in the next revision.
[1] https://lore.kernel.org/rust-for-linux/DA9JTYA0EQU8.26M0ZX80FOBWY@nvidia.com/
Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
---
Alexandre Courbot (4):
rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`
rust: alloc: implement `Borrow` and `BorrowMut` for `Arc` types
rust: alloc: implement `Borrow` and `BorrowMut` for `KBox`
rust: alloc: implement `Borrow` and `BorrowMut` for `CString`
rust/kernel/alloc/kbox.rs | 21 +++++++++++++++++++++
rust/kernel/alloc/kvec.rs | 19 +++++++++++++++++++
rust/kernel/str.rs | 13 +++++++++++++
rust/kernel/sync/arc.rs | 21 ++++++++++++++++++++-
4 files changed, 73 insertions(+), 1 deletion(-)
---
base-commit: 7a17bbc1d952057898cb0739e60665908fbb8c72
change-id: 20250531-borrow_impls-8dfef3fcee93
Best regards,
--
Alexandre Courbot <acourbot@...dia.com>
Powered by blists - more mailing lists