-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add #[repr(transparent)]
to PathBuf
#72838
Comments
Can you cite which conversion you are trying to provide externally from std which would be enabled by such? I presuming you mean that PathBuf is internally an OsString, not OsStr? It also looks like both |
Sure. I'm actually backporting the APIs from 1.44 to 1.31 (the MSRV for this crate). Obviously the repr attribute wouldn't apply to older versions, but if any get stabilized later on, it would allow backporting with safety guarantees. The Realistically, I don't see why the attribute shouldn't be added, though. I took a quick look through the impls, and it would be nearly impossible to have any other internal representation without removing some of these. |
Ah, I see. Technically you could ptr::read and be quite careful to not drop anything, but I suppose that's not better than transmuting. I would suggest filing a PR which can then be r?'d for someone on the libs team to approve. |
Will do. I'll also add it to |
Closing per #72841 (review). |
The fact that
PathBuf
is internally anOsStr
is currently noted as an implementation detail in comments. However, a number of methods clearly indicate (in documentation) that it is stored as such, and onePathBuf::into_os_str()
implicitly requires it, as it would be inefficient to do it otherwise.Would it make sense to add
#[repr(transparent)]
toPathBuf
to externally stabilize this guarantee? It would also allow me (as the maintainer of the standback crate) to usetransmute
in a guaranteed manner.The text was updated successfully, but these errors were encountered: