Skip to content

Conversation

@thaliaarchi
Copy link
Contributor

Currently, the std::os::{platform}::ffi::{OsStringExt, OsStrExt} traits have quite a bit of duplication, since there are several platforms using only three implementations of OsString/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 Windows ffi module.

Move these modules to std::sys::ffi::{bytes, windows, utf8} and publicly reexport them as each platform's std::os::{platform}::ffi module. To handle the differing documentation, use cfg_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 module windows instead of wtf8, but if UEFI wants to grow its own documentation, we could rename it to wtf8 and create conditionally-included Markdown files for both, as I assume it would have many changes. For now, utf8 has 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

@rustbot
Copy link
Collaborator

rustbot commented Oct 23, 2025

joboet is currently at their maximum review capacity.
They may take a while to respond.

@rustbot rustbot added O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants