From: Alexandre Courbot <acourbot@nvidia.com>
To: "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>,
"Benno Lossin" <lossin@kernel.org>,
"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,
Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH v2 0/4] rust: a few common Borrow/BorrowMut implementations
Date: Fri, 13 Jun 2025 22:46:07 +0900 [thread overview]
Message-ID: <20250613-borrow_impls-v2-0-6120e1958199@nvidia.com> (raw)
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 second revision adds examples to each impl block as requested. I am
personally not quite convinced that they are needed, as they just
illustrate the basic usage of `Borrow`, but have added them to this
revision so we can decide whether we want them or not.
[1] https://lore.kernel.org/rust-for-linux/DA9JTYA0EQU8.26M0ZX80FOBWY@nvidia.com/
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v2:
- Rebase on top of v6.16-rc1.
- Improve commit messages. (thanks Benno!)
- Add examples on each impl block.
- Link to v1: https://lore.kernel.org/r/20250601-borrow_impls-v1-0-e1caeb428db4@nvidia.com
---
Alexandre Courbot (4):
rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`
rust: sync: implement `Borrow` and `BorrowMut` for `Arc` types
rust: alloc: implement `Borrow` and `BorrowMut` for `KBox`
rust: str: implement `Borrow` and `BorrowMut` for `CString`
rust/kernel/alloc/kbox.rs | 61 ++++++++++++++++++++++++++++++++++
rust/kernel/alloc/kvec.rs | 57 ++++++++++++++++++++++++++++++++
rust/kernel/str.rs | 49 +++++++++++++++++++++++++++
rust/kernel/sync/arc.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 250 insertions(+), 1 deletion(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250531-borrow_impls-8dfef3fcee93
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
next reply other threads:[~2025-06-13 13:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-13 13:46 Alexandre Courbot [this message]
2025-06-13 13:46 ` [PATCH v2 1/4] rust: alloc: implement `Borrow` and `BorrowMut` for `Vec` Alexandre Courbot
2025-06-14 19:19 ` Benno Lossin
2025-06-15 12:36 ` Alexandre Courbot
2025-06-15 13:16 ` Miguel Ojeda
2025-06-15 15:28 ` Benno Lossin
2025-06-13 13:46 ` [PATCH v2 2/4] rust: sync: implement `Borrow` and `BorrowMut` for `Arc` types Alexandre Courbot
2025-06-14 19:20 ` Benno Lossin
2025-06-13 13:46 ` [PATCH v2 3/4] rust: alloc: implement `Borrow` and `BorrowMut` for `KBox` Alexandre Courbot
2025-06-14 19:20 ` Benno Lossin
2025-06-13 13:46 ` [PATCH v2 4/4] rust: str: implement `Borrow` and `BorrowMut` for `CString` Alexandre Courbot
2025-06-14 19:21 ` Benno Lossin
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=20250613-borrow_impls-v2-0-6120e1958199@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--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=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).