As far as I’m understanding the requirement for structural pinning, slices in Rust do meet all the requirements for pinning to be structural over their elements.
Unpinimpl seems fitting
Dropis not explicitly implemented (so it can’t do evil) and panics from dropping the elements results in no destructor calls of succeeding elements being skipped (except for when the program aborts).
- There are no operations leading to data being moved out of the slice when pinned (in fact, there are no operations at all handling pinned slices).
Yet I’m sorely missing functions in the standard library (or any crate I could find, for that matter—please point out any if they exist) with these signatures (with the obvious functionality)
(slice: Pin<&mut [T]>, index: usize) -> Pin<&mut T>
(self: Pin<&mut [T]>) -> impl Iterator<Item = Pin<&mut T>>
Am I missing something that makes these unsound? Are there any previous discussions on adding something to the standard library for this?
My actual goal here is just to have an owned collection of
T: !Unpin values that allows me to obtain
Pin<&mut T> references to its elements through indexing. If the operations described above were possible, I could use
Pin<Box<[T]>> for this purpose. But perhaps (especially in case I’m missing some fundamental reasons against doing this with the actual slice type) there are alternative structually-pinned-collection-types out there; in which case, please point me to a crate.