Proposed refactoring to implement core::io
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
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:
- https://github.com/QuiltOS/core-io
- https://crates.io/crates/core_io
- https://github.com/jethrogb/rust-core_io/issues/3
- https://github.com/rust-lang/rust/pull/33149
- https://github.com/rust-lang/rust/pull/37133
- https://internals.rust-lang.org/t/refactoring-std-for-ultimate-portability/4301
- https://github.com/BurntSushi/byteorder/issues/51
- https://github.com/rust-lang/rfcs/blob/master/text/0517-io-os-reform.md#coreio
- https://github.com/rust-lang/rfcs/pull/517
- https://github.com/rust-lang-nursery/error-chain/pull/157
- https://internals.rust-lang.org/t/crate-evaluation-for-2017-06-27-error-chain/5362/25
- https://crates.io/crates/genio
- https://github.com/rust-embedded/rfcs/issues/22
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:
- Move rust/src/libstd/io/*.rs to a new directory rust/src/libio_template
- Add a new rust/src/libstd/io/mod.rs with just an include!("../../libio_template/mod.rs").
- Add new crate rust/src/libio_nostd, which will also include! libio_template.
- Add cfg feature "libio_for_std" to both libstd and libio_nostd, with it enabled and disabled by default respectively.
- Patch libio_template to compile in libstd and libio_nostd.
- 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the current rust/src/libstd/io/*.rs sources and the linked prior art on core::io and std portability. Explore the proposed rust/src/libio_template and rust/src/libio_nostd layout, then determine whether a prototype or formal RFC can support std and no_std while keeping the std::io API identical.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100