A few times now, I've wanted some specific helper that kinda needs sibling-referential borrowing. This has happened in network protocol work, where I have
'static data (typically
bytes::Bytes, but it could be
Vec<u8>), and a parsed structure that holds a bunch of references into the data. I'd then like to pass the parsed structure around, which of course is tricky since currently (AFAIK) there aren't really facilities to do that -- and I don't think sibling/self-referential lifetimes are particularly high on the priority list?
So then I've
transmuted() the lifetime of the parsed data away in order to basically store the data and the parsed structure together in a struct, making the data member private and transmuting the parsed structure to have a
'static lifetime, with a way to get a reference to the parsed structure with a lifetime atttached to the wrapper. But I'd like to know if this use of unsafe is sound -- and if there is, would it make sense to package this abstraction into a crate which maybe down the line could go into
There's an example in the
ResponseData type. I guess a safe interface for this would somewhat hinge on the splitting API that
Bytes provides. A generic version could maybe be called
Backed, unless someone can come up with a better name.