Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Document pointer cast safety in std::path #45910
I'm curious about the unsafe cast in Path.
From what I understand: this works because Path is a single member struct containing only the type it's being reinterpreted as.
My original question on #rust IRC was: Is this always guaranteed to be correct (in Rust) in terms of memory layout?
The discussion seemed to hint at that this is in fact not a guarantee, but that std is in a unique position being developed in concert with the language and any future breakage would be patched when it occurs.
I would love some clarification if this usage is correct or to what degree it is not. I'd also suggest we add clarification around this case with comments or support functions to aid future spelunking into std.
@cramertj excellent, thank you!
The tracking issue seems to indicate things going slowly. Adding a comment might still be a good idea for now.
Reading the RFC, it mentions at least ARM64 where there might be layout differences. But according to platform support, std shows up as supported as a Tier 2 platform. This implies that at least for now, this pattern in this instance (
This is my understanding as well.
I believe it is safe with either repr(transparent) or repr(C), the latter of which is stable. The