I have a handle from C and on this handle one can do some index operations [0...size]. Neither the handle nor the underlying C data structure is an array or contiguous. They are representations for some other contiguous memory but that memory cannot be de-referenced. So my input is something like this:
handle: *const void,
On the rust side I would like to have a slice like representation where I can mutably borrow into those index ranges. So i want to do some operation like heap[0..20] or heap.split_at(median) and as an output I'd like to have something like this:
The lifetime ties each HeapSlice to the Heap it was derived from. If you want disjoint slices of the same Heap, you'll want to add a method like split_at_mut, which lets you take one slice and divide it in two.
I don't think so. The Heap should own the resources, the HeapSlices should borrow from Heap. If you do that, you don't need to manage the slices going out of scope; the compiler will ensure a Heap outlives any slices derived from it.