Allow recovery of slices used in SliceStorage and SliceStorageMut
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
The `Storage` and `StorageMut` traits require implementation of `as_slice` and `as_mut_slice` methods, respectively. However, the returned slices have the lifetime of the reference to the storage object, not the underlying lifetime. No methods exist in `MatrixSlice` for recovery of the original slice.
It is sometimes necessary that the slice needs to be recovered. For example, when trying to reclaim the mutable slice transferred to a `SliceStorageMut` object to use `MatrixSliceMut` and friends. Consider the following example:
```rust
struct Buffer<'buf> {
buffer: &'buf [f64],
// ...
}
impl<'buf> Buffer<'buf> {
fn to_vector_mut(mut self) -> Vector<'buf>{
Vector { vector: DVectorSliceMut::from(self.buffer) }
}
}
struct Vector<'buf> {
vector: DVectorSliceMut<'buf, f64>,
// ...
}
impl<'buf> Vector<'buf> {
fn to_buffer(mut self) -> Buffer<'buf> {
// Can't implement. No way to extract the &'buf mut [f64] slice.
}
}
```
Is such a feature possible to implement? I also have [this](https://stackoverflow.com/questions/68023386/extract-original-slice-from-slicestorage-and-slicestoragemut) open issue on SO.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.