Hi everyone,
I have a use case that, from my understanding, should be possible with Pin. My goal is to have a struct that contains an Box<[u8]> buffer as one field, and another field that is a slice of that buffer.
(actually the slices will be nested deeper inside the type of the other field, but I simplified it for this question).
So something like
struct S<'a> {
buf: Pin<Box<[u8]>>,
slice: Option<&'a [u8]>,
}
The non-working short example is here:
I can only find examples on how to reference fields by pinning the whole struct, which should not be necessary, right? The [u8] inside the box cannot move, as the Pin should make it impossible to get to a &mut [u8] (safely). And as the Box is on the heap, I can move around my parent struct S freely without affecting the [u8] location in memory.
How can I get this code to compile (and also work correctly )?