rust: a few common Borrow/BorrowMut implementations
Status from this message: Applied to alloc-next, thanks!
Get series with b4
b4 am [email protected] change-id 20250531-borrow_impls-8dfef3fcee93Versions newest first
- v4 Latest7 patches 6 repliesApplied
- v34 patches 4 repliesSuperseded
- v24 patches 7 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 4 patches | 12 replies | Superseded |
Changes in v4 from the cover letter
- Implement from_bytes_with_nul_mut to avoid unsafe block in doctest.
- Make from_bytes_with_nul_unchecked_mut const and use transmute.
- Use more explicit names for variables in doctests.
- Link to v3: https://lore.kernel.org/r/[email protected]
Patches in v4 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`rust/ | +53 | 1 reply | |
| 2/7 | rust: sync: implement `Borrow` and `BorrowMut` for `Arc` typesrust/ | +77 | 1 reply | |
| 3/7 | rust: alloc: implement `Borrow` and `BorrowMut` for `KBox`rust/ | +57 | 1 reply | |
| 4/7 | rust: str: make `from_bytes_with_nul_unchecked_mut` construst/ | +1 | 3 replies | |
| 5/7 | rust: str: use transmute in `from_bytes_with_nul_unchecked_mut`rust/ | +1 | 0 replies | |
| 6/7 | rust: str: implement `from_bytes_with_nul_mut`rust/ | +31 | 0 replies | |
| 7/7 | rust: str: implement `Borrow` and `BorrowMut` for `CString`rust/ | +45 | 0 replies |
Reviews trailers per patch
5 of 7 patches have a Reviewed-by or Acked-by.
| Patch | Alice Ryhl | Benno Lossin |
|---|---|---|
| 1/7 | R-b | R-b |
| 2/7 | R-b | R-b |
| 3/7 | R-b | R-b |
| 4/7 | R-b | |
| 5/7 | ||
| 6/7 | ||
| 7/7 | R-b | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v4 0/7] 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].
In order to avoid an unsightly unsafe block in the doctest, this also implements from_bytes_with_nul_mut. from_bytes_with_nul and from_bytes_with_nul_unchecked_mut already exist, so it looked strange to not have it anyway.
While doing this, I noticed that from_bytes_with_nul_unchecked_mut was not const and not using transmute, which I attributed to the absence of the const_mut_refs feature at the time the code was written. I've tentatively fixed that, but my assumption for doing this might be wrong so a double-check from someone more familiar with the timeline of this code would be appreciated.
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
---
Changes in v4:
- Implement from_bytes_with_nul_mut to avoid unsafe block in doctest.
- Make from_bytes_with_nul_unchecked_mut const and use transmute.
- Use more explicit names for variables in doctests.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Remove undeeded first line of doccomments.
- Link to v2: https://lore.kernel.org/r/[email protected]
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/[email protected]
---
Alexandre Courbot (7):
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: make from_bytes_with_nul_unchecked_mut const
rust: str: use transmute in from_bytes_with_nul_unchecked_mut
rust: str: implement from_bytes_with_nul_mut
rust: str: implement Borrow and BorrowMut for CString
rust/kernel/alloc/kbox.rs | 57 +++++++++++++++++++++++++++++++ rust/kernel/alloc/kvec.rs | 53 +++++++++++++++++++++++++++++ rust/kernel/str.rs | 86 ++++++++++++++++++++++++++++++++++++++++++----- rust/kernel/sync/arc.rs | 78 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 265 insertions(+), 9 deletions(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250531-borrow_impls-8dfef3fcee93
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>