Conversation
9f3a024 to
6c03582
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the buffered I/O implementation as the second stage of a larger refactoring effort. It reimplements BufReader with improved buffer management, adds BufWriter and LineWriter implementations, and reorganizes the module structure for better maintainability.
Key changes:
- Reorganized code into separate
read,write, andseekmodules for better separation of concerns - Reimplemented
BufReaderto useBox<[MaybeUninit<u8>]>whenallocis enabled, andheapless::Vecwith fixed capacity when disabled - Added
BufWriterandLineWriterwith similar dual-mode buffer management - Enhanced build configuration using
autocfgto detectmaybe_uninit_slicefeature availability
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Updated to use new module structure, bumped edition to 2024, added DEFAULT_BUF_SIZE constant |
| src/prelude.rs | Updated import paths to use crate:: instead of super:: |
| src/read/mod.rs | Extracted Read trait and related functionality from lib.rs with additional helper functions |
| src/read/impls.rs | Implementations of Read/BufRead for standard types like slices, Box, VecDeque |
| src/write/mod.rs | New Write trait module with formatting support |
| src/write/impls.rs | Implementations of Write for standard types |
| src/seek/mod.rs | New Seek trait module extracted from lib.rs |
| src/seek/impls.rs | Forwarding implementations for &mut T and Box |
| src/buffered/mod.rs | Added exports for BufWriter, LineWriter, and IntoInnerError |
| src/buffered/bufreader/mod.rs | Reimplemented BufReader with new buffer abstraction |
| src/buffered/bufreader/buffer.rs | New internal buffer implementation supporting both alloc and no-alloc modes |
| src/buffered/bufwriter/mod.rs | New BufWriter implementation with dual-mode buffering |
| src/buffered/linewriter/mod.rs | New LineWriter wrapper around BufWriter |
| src/buffered/linewriter/shim.rs | Internal line-buffering logic implementation |
| build.rs | Added autocfg probe for maybe_uninit_slice feature |
| Cargo.toml | Updated axerrno to 0.2, added heapless and memchr dependencies, changed edition to 2024 |
| README.md | Enhanced documentation with feature descriptions and limitations |
| rustfmt.toml | New formatting configuration file |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9ed9f57 to
a0312c6
Compare
|
Typos found by Copilot has been reported upstream. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a0312c6 to
0f46775
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.buf.copy_within(self.pos.., 0); | ||
| self.filled -= self.pos; |
There was a problem hiding this comment.
Buffer::backshift updates pos/filled but (under cfg(borrowedbuf_init)) it does not update initialized. After shifting the underlying slice left, the first initialized bytes are no longer guaranteed to be initialized, so later BorrowedBuf::set_init(self.initialized) can over-report initialized bytes and cause UB for Read impls that don't fully initialize the buffer. Track the old pos and subtract it from initialized (or otherwise recompute it) when borrowedbuf_init is enabled.
| self.buf.copy_within(self.pos.., 0); | |
| self.filled -= self.pos; | |
| let old_pos = self.pos; | |
| self.buf.copy_within(old_pos.., 0); | |
| self.filled -= old_pos; | |
| #[cfg(borrowedbuf_init)] | |
| { | |
| self.initialized -= old_pos; | |
| } |
Depends: #8
This is the second stage of refactoring, extracted from #4.
Changes
BufReaderallocfeature is enabled, use aBox<[MaybeUninit<u8>]>as buffer backend and useheapless::Vecwhich has a capacity limit ifallocfeature is disabled.BufWriterandLineWriterBufReader, useheapless::Vecinstead ofalloc::vec::Vecifallocfeature is disabled but the capacity is fixed.autocfgto check ifmaybe_uninit_sliceis stabilized on current compiler