[PATCH v3 0/4] rust: a few common Borrow/BorrowMut implementations

Alexandre Courbot posted 4 patches 3 months, 3 weeks ago
There is a newer version of this series
rust/kernel/alloc/kbox.rs | 57 ++++++++++++++++++++++++++++++++++
rust/kernel/alloc/kvec.rs | 53 ++++++++++++++++++++++++++++++++
rust/kernel/str.rs        | 45 +++++++++++++++++++++++++++
rust/kernel/sync/arc.rs   | 78 ++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 232 insertions(+), 1 deletion(-)
[PATCH v3 0/4] rust: a few common Borrow/BorrowMut implementations
Posted by Alexandre Courbot 3 months, 3 weeks ago
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 v3:
- Remove undeeded first line of doccomments.
- Link to v2: https://lore.kernel.org/r/20250613-borrow_impls-v2-0-6120e1958199@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 | 57 ++++++++++++++++++++++++++++++++++
 rust/kernel/alloc/kvec.rs | 53 ++++++++++++++++++++++++++++++++
 rust/kernel/str.rs        | 45 +++++++++++++++++++++++++++
 rust/kernel/sync/arc.rs   | 78 ++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 232 insertions(+), 1 deletion(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250531-borrow_impls-8dfef3fcee93

Best regards,
-- 
Alexandre Courbot <acourbot@nvidia.com>