rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] rust: a few common Borrow/BorrowMut implementations
@ 2025-06-01  3:00 Alexandre Courbot
  2025-06-01  3:00 ` [PATCH 1/4] rust: alloc: implement `Borrow` and `BorrowMut` for `Vec` Alexandre Courbot
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Alexandre Courbot @ 2025-06-01  3:00 UTC (permalink / raw)
  To: Danilo Krummrich, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross
  Cc: rust-for-linux, linux-kernel, Alexandre Courbot

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@nvidia.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@nvidia.com>


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-06-13  7:45 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).