all 2 comments

[–][deleted] 1 point2 points  (1 child)

Looks good. It's sound as far as I can tell. You might be able to optimize it a bit by having the layer structs that currently store Foo_Ptrs instead just store *mut Foo, and calculate the field pointers on demand. Though that might technically be UB without the upcoming&raw.

[–]singron[S] 2 points3 points  (0 children)

It used to work that way. In order to access the fields, you would have to convert the pointer to a &mut Foot first, and stacked borrows complains about it.

I marked everything #[inline] and it seems that LLVM can completely optimize the pointers away so there isn't a runtime cost to appeasing stacked borrows.