Preserve data lifetime in SliceRef/SliceMut subslicing - #47
Open
tim-harding wants to merge 1 commit into
Open
Conversation
Sub-slicing methods were only reachable on `SliceRef`/`SliceMut` through `Deref`, so `slice_ref.split_at(n)` desugared to `(&*slice_ref).split_at(n)` and bound the result to the local rather than to the data. That made the standard batching-iterator pattern impossible. Add `self`-consuming inherent methods on `SliceRef<'a, T>` and `SliceMut<'a, T>`, which shadow the `Deref`-reached ones and return `'a`. `SoaIndex` now takes a `SliceRef`/`SliceMut` so the output lifetime rides in on the argument, keeping the whole path safe. `Slice`'s methods delegate, which also removes `split_at_parts`. `SliceMut` is not `Copy`, so consuming shadows cost reborrowing. Only the methods named in the issue are shadowed there; `iter_mut` and friends still reborrow, and `as_mut_slice` is the explicit reborrow for the rest. Fixes #45 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Owner
Author
|
I'll sleep on this as it is a breaking change with some consequences to API ergonomics. |
|
Please hold it for a few days, up to a week. I'l try do an alternative solution. |
|
No luck. My idea would not work. I'll publish explanation in the issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sub-slicing methods were only reachable on
SliceRef/SliceMutthroughDeref, soslice_ref.split_at(n)desugared to(&*slice_ref).split_at(n)and bound the result to the local rather than to the data. That made the standard batching-iterator pattern impossible.Add
self-consuming inherent methods onSliceRef<'a, T>andSliceMut<'a, T>, which shadow theDeref-reached ones and return'a.SoaIndexnow takes aSliceRef/SliceMutso the output lifetime rides in on the argument, keeping the whole path safe.Slice's methods delegate, which also removessplit_at_parts.SliceMutis notCopy, so consuming shadows cost reborrowing. Only the methods named in the issue are shadowed there;iter_mutand friends still reborrow, andas_mut_sliceis the explicit reborrow for the rest.Fixes #45