Skip to content

Proposed refactoring to implement core::io #2262

Open
@fluffysquirrels

Description

@fluffysquirrels

Label: T-libs

There have of course been several efforts to refactor std::io to make it usable without std as core::io or similar.

Some links to prior art from a few hours of searching:

From what I can see all efforts are currently stalled, but I'd like to make progress on using std::io in a no_std environment. My use case is a crate I'm writing that uses std::io::{Read, Write}, and I want it to build with std and when no_std.

As mentioned in https://internals.rust-lang.org/t/refactoring-std-for-ultimate-portability/4301, there are circular dependencies between std::io and the rest of std.

I have an idea that I've not seen mentioned: use conditional compilation in the std::io module to enable use without std. Steps required in more detail:

  1. Move rust/src/libstd/io/*.rs to a new directory rust/src/libio_template
  2. Add a new rust/src/libstd/io/mod.rs with just an include!("../../libio_template/mod.rs").
  3. Add new crate rust/src/libio_nostd, which will also include! libio_template.
  4. Add cfg feature "libio_for_std" to both libstd and libio_nostd, with it enabled and disabled by default respectively.
  5. Patch libio_template to compile in libstd and libio_nostd.
  6. All done. no_std consumers can use libio_nostd, libstd API should be identical, future std::io patches must be correct both in libstd and libio_nostd.

The ideal solution, as proposed in https://internals.rust-lang.org/t/refactoring-std-for-ultimate-portability/4301, is probably a careful refactoring to decouple std, but that seems like a lot of work, which has already stalled once. A templated approach allows quick progress and can be eradicated progressively as more parts of std::io are refactored out of std.

I'm willing to work on a prototype branch or more formal RFC if there is interest from the libs team.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-input-outputProposals relating to std{in, out, err}.A-no_stdProposals relating to #[no_std].A-traits-libstdStandard library trait related proposals & ideasT-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions