about summary refs log tree commit diff
path: root/library/std/src/io/buffered
AgeCommit message (Collapse)AuthorLines
2025-08-26remove deprecated Error::description in implsMarijn Schouten-16/+3
2025-08-17bufreader::Buffer::backshift: don't move the uninit bytesbinarycat-1/+1
previous code was perfectly sound because of MaybeUninit, but it did waste cycles on copying memory that is known to be uninitialized.
2025-04-01io: Avoid Avoid marking bytes as uninit in `BufReader::peek`Benoît du Garreau-1/+0
2025-03-16Rollup merge of #137890 - lolbinarycat:docs-bufreader-peek-consume, ↵许杰友 Jieyou Xu (Joe)-1/+5
r=Mark-Simulacrum doc: clarify that consume can be called after BufReader::peek tracking issue #128405
2025-03-02doc: clarify that consume can be called after BufReader::peekbinarycat-1/+5
2025-02-28Fix logic error in Buffer::read_more()Will Woods-2/+2
Buffer::read_more() is supposed to refill the buffer without discarding its contents, which are in the range `pos .. filled`. It mistakenly borrows the range `pos ..`, fills that, and then increments `filled` by the amount read. This overwrites the buffer's existing contents and sets `filled` to a too-large value that either exposes uninitialized bytes or walks off the end of the buffer entirely. This patch makes it correctly fill only the unfilled portion of the buffer, which should maintain all the type invariants and fix the test failure introduced in commit b1196717fcb.
2025-02-28Tweak BufReader::peek() doctest to expose bug in Buffer::read_more()Will Woods-3/+3
This patch makes BufReader::peek()'s doctest call read_more() to refill the buffer before the inner reader hits EOF. This exposes a bug in read_more() that causes an out-of-bounds slice access and segfault.
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-1/+1
2024-12-21Avoid short writes in LineWriterChris Denton-6/+21
Also update the tests to avoid testing implementation details.
2024-11-26std: update internal uses of `io::const_error!`joboet-3/+3
2024-09-29Fix std tests for wasm32-wasip2 targetNicola Krumschmidt-1/+2
2024-09-28Rollup merge of #125404 - a1phyr:fix-read_buf-uses, r=workingjubileeMatthias Krüger-2/+4
Fix `read_buf` uses in `std` Following lib-team decision here: https://github.com/rust-lang/rust/issues/78485#issuecomment-2122992314 Guard against the pathological behavior of both returning an error and performing a read.
2024-09-24Pre-allocate buffers in `File::open_buffered` and `create_buffered`Josh Stone-1/+29
2024-09-23Fix `io::BufReader` uses of `read_buf`Benoît du Garreau-2/+4
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-09-15Rollup merge of #130042 - lolbinarycat:bufreaker_peek_eof, r=AmanieuStuart Cook-4/+12
properly handle EOF in BufReader::peek previously this would cause an infinite loop due to it being unable to read `n` bytes.
2024-09-09Add missing `#[allow(missing_docs)]` on hack functions in allocUrgau-0/+1
2024-09-06properly handle EOF in BufReader::peekbinarycat-4/+12
previously this would cause an infinite loop due to it being unable to read `n` bytes.
2024-08-28allow BufReader::peek to be called on unsized typesbinarycat-0/+2
2024-08-05implement BufReader::peekbinarycat-0/+55
2024-07-29Reformat `use` declarations.Nicholas Nethercote-15/+13
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-19/+23
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-14std: Unsafe-wrap std::ioJubilee Young-3/+5
2024-07-12Use ManuallyDrop in BufWriter::into_partsBen Kimock-7/+17
2024-06-20Convert some module-level `//` and `///` comments to `//!`.Nicholas Nethercote-10/+11
This makes their intent and expected location clearer. We see some examples where these comments were not clearly separate from `use` declarations, which made it hard to understand what the comment is describing.
2024-04-14Rollup merge of #120900 - marcospb19:std-use-seek-stream-position, ↵Guillaume Gomez-2/+5
r=joshtriplett std: use `stream_position` where applicable by replacing `seek(SeekFrom::Current(0))` calls
2024-04-11Factor some common `io::Error` constantsBenoît du Garreau-6/+1
2024-04-10Auto merge of #122393 - a1phyr:specialize_read_buf_exact, r=joboetbors-0/+8
Specialize many implementations of `Read::read_buf_exact` This makes all implementations of `Read` that have a specialized `read_exact` implementation also have one for `read_buf_exact`.
2024-03-20resolve clippy errorsonur-ozkan-4/+3
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-12Specialize many implementations of `Read::read_buf_exact`Benoît du Garreau-0/+8
2024-03-09Rollup merge of #121403 - kornelski:io-oom, r=dtolnayGuillaume Boisseau-1/+1
impl From<TryReserveError> for io::Error There's an obvious mapping between these two errors, and it makes I/O code less noisy. I've chosen to use simple `ErrorKind::OutOfMemory` `io::Error`, without keeping `TryReserveError` for the `source()`, because: * It matches current uses in libstd, * `ErrorData::Custom` allocates, which is a risky proposition for handling OOM errors specifically. * Currently `TryReserveError` has no public fields/methods, so it's usefulness is limited. How allocators should report errors, especially custom and verbose ones is still an open question. Just in case I've added note in the doccomment that this may change. The compiler forced me to declare stability of this impl. I think this implementation is simple enough that it doesn't need full-blown stabilization period, and I've marked it for the next release, but of course I can adjust the attribute if needed.
2024-03-03Fix quadratic behavior of repeated vectored writesJan Verbeek-27/+39
Some implementations of `Write::write_vectored` in the standard library (`BufWriter`, `LineWriter`, `Stdout`, `Stderr`) check all buffers to calculate the total length. This is O(n) over the number of buffers. It's common that only a limited number of buffers is written at a time (e.g. 1024 for `writev(2)`). `write_vectored_all` will then call `write_vectored` repeatedly, leading to a runtime of O(n²) over the number of buffers. The fix is to only calculate as much as needed if it's needed.
2024-02-21Remove unnecessary map_errKornel-1/+1
2024-02-20Delete architecture-specific memchr code in std::sysArthur Carcano-1/+1
Currently all architecture-specific memchr code is only used in `std::io`. Most of the actual `memchr` capacity exposed to the user through the slice API is instead implemented in core::slice::memchr. Hence this commit deletes memchr from std::sys[_common] and replace calls to it by calls to core::slice::memchr functions. This deletes (r)memchr from the list of symbols linked to libc.
2024-02-19Remove an old hack for rustdocPavel Grigorenko-4/+2
2024-02-11std: use `stream_position` where applicableJoão Marcos P. Bezerra-2/+5
by replacing `seek(SeekFrom::Current(0))` calls
2024-01-29Handle out of memory errors in io:Read::read_to_end()Kornel-0/+1
2023-11-19Rollup merge of #116750 - fintelia:seek_seek_relative, r=Mark-SimulacrumTakayuki Maeda-0/+10
Add Seek::seek_relative The `BufReader` struct has a `seek_relative` method because its `Seek::seek` implementation involved dumping the internal buffer (https://github.com/rust-lang/rust/issues/31100). Unfortunately, there isn't really a good way to take advantage of that method in generic code. This PR adds the same method to the main `Seek` trait with the straightforward default method, and an override for `BufReader` that calls its implementation. _Also discussed in [this](https://internals.rust-lang.org/t/add-seek-seek-relative/19546) internals.rust-lang.org thread._
2023-10-20Specialize `Bytes<R>::next` when `R` is a `BufReader`.Nicholas Nethercote-5/+20
This reduces the runtime for a simple program using `Bytes::next` to iterate through a file from 220ms to 70ms on my Linux box.
2023-10-14Add Seek::seek_relativeJonathan Behrens-0/+10
2023-09-03Use std::io::Error::is_interrupted everywhereBen Kimock-1/+1
2023-07-06Rollup merge of #112008 - intruder-kat:master, r=NilstriebMichael Goulet-2/+2
Fix incorrect documented default bufsize in bufreader/writer
2023-06-17Extend io::copy buffer reuse to BufReader tooThe 8472-1/+1
previously it was only able to use BufWriter. This was due to a limitation in the BufReader generics that prevented specialization. This change works around the issue by using `where Self: Read` instead of `where I: Read`. This limits our options, e.g. we can't access BufRead methods, but it happens to work out if we rely on some implementation details.
2023-05-26Fix incorrect documented default bufsize in bufreader/writerKathryn R-2/+2
2023-05-01Relax implicit `W: Sized` bound on `LineWriter<W>`Maybe Waffle-27/+29
2023-05-01Relax implicit `W: Sized` bound on `BufWriter<W>`Maybe Waffle-68/+70
2023-05-01Relax implicit `R: Sized` bound on `BufReader<R>`Maybe Waffle-12/+15
2023-04-26rewrite: line_long_tail_not_flushed descriptionJosh Soref-3/+4
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-26rewrite: long_line_flushed descriptionJosh Soref-3/+3
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-06Remove an unnecessary `mut` in `BufWriter::into_parts`.管唯宇-1/+1
`ptr::read` takes `*const T` so `&mut` is not necessary.