Unify OsStringExt/OsStrExt traits across platforms
#148050
Open
+161
−248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the
std::os::{platform}::ffi::{OsStringExt, OsStrExt}traits have quite a bit of duplication, since there are several platforms using only three implementations ofOsString/OsStr(bytes, WTF-8, and recently now UTF-8). To deal with this, the bytes platforms reexport the Unix ext traits, but provide their own module-level documentation. This documentation has grown slightly out of sync and some platforms forgot to include it entirely. UEFI, as it has much shared background with Windows, simply reexports the whole Windowsffimodule.Move these modules to
std::sys::ffi::{bytes, windows, utf8}and publicly reexport them as each platform'sstd::os::{platform}::ffimodule. To handle the differing documentation, usecfg_select!. The bytes impl has the examples in the module docs, to be reused, but could now be moved to the relevant traits. Since the Windows docs have much Windows-specific wording, I have named that modulewindowsinstead ofwtf8, but if UEFI wants to grow its own documentation, we could rename it towtf8and create conditionally-included Markdown files for both, as I assume it would have many changes. For now,utf8has Motor OS–specific docs, but I intend to generalize it when I add WASIp2 and Redox OS support (see #147932).This is related to the effort in #117276, but takes a different approach by necessity of the traits and documentation being public, instead of an internal abstraction layer. I think it turned out reasonably and is better than what we currently have, but I am open to other approaches. The primary downside is that there are cfg gates that must be kept in sync in two places: in library/core/src/os/mod.rs and the docs of library/std/src/sys/ffi/bytes.rs.
The two-step diff makes it slightly more clear that the Unix traits were not changed; only moved.
r? @joboet