about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2025-09-28Fix typoSebastian Speitel-1/+1
2025-09-16Fix spelling of "adaptor"Joe Birr-Pixton-1/+1
These docs are in en_US, so "adapter" is the correct spelling (and indeed used in the next line.)
2025-09-08std: make address resolution weirdness local to SGXjoboet-0/+3
2025-08-26remove deprecated Error::description in implsMarijn Schouten-25/+3
2025-08-21Rollup merge of #145525 - typesanitizer:vg/doc, r=Mark-SimulacrumJacob Pratt-1/+1
stdlib: Replace typedef -> type alias in doc comment 'typedef' is jargon from C and C++. Since the Rust reference uses the term [type alias](https://doc.rust-lang.org/reference/items/type-aliases.html), this patch changes the doc comment in io/error.rs to also use 'type alias'.
2025-08-20Rollup merge of #145006 - ginnyTheCat:docs-skip-until, r=ibraheemdevJacob Pratt-2/+7
Clarify EOF handling for `BufRead::skip_until` This aligns `BufRead::skip_until`'s description more with `BufRead::read_until` in terms of how it handles EOF and extends the doctest to include this behavior.
2025-08-19Rollup merge of #145538 - lolbinarycat:std-bufreader-buffer-backshift-less, ↵许杰友 Jieyou Xu (Joe)-1/+1
r=tgross35 bufreader::Buffer::backshift: don't move the uninit bytes previous code was perfectly sound because of MaybeUninit, but it did waste cycles on copying memory that is known to be uninitialized.
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-08-17stdlib: Replace typedef -> type alias in doc commentVarun Gandhi-1/+1
2025-08-16library: Migrate from `cfg_if` to `cfg_select`Josh Triplett-3/+4
Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro. This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does. Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation): ``` '<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e ``` This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-08-06Clarify EOF handling for `BufRead::skip_until`ginnyTheCat-2/+7
2025-07-09core: Remove `BorrowedCursor::init_ref` methodBenoît du Garreau-3/+3
This method was not really useful: at no point one would only need to read the initialized part of the cursor without mutating it.
2025-07-01Update version placeholdersJosh Stone-1/+1
2025-06-25make `tidy-alphabetical` use a natural sortFolkert de Vries-1/+1
2025-06-20Add diagnostic items for ClippySamuel Tardieu-0/+2
2025-06-10Rollup merge of #142102 - kiseitai3:141714_stdin_read_to_string_docs, r=tgross35León Orell Valerian Liehr-0/+40
docs: Small clarification on the usage of read_to_string and read_to_end trait methods Small clarification on the usage of read_to_string and read_to_end trait methods. The goal is to make it clear that these trait methods will become locked up if attempting to read to the end of stdin (which is a bit non-sensical unless the other end closes the pipe). Fixes: rust-lang/rust#141714
2025-06-10docs: Small clarification on the usage of read_to_string and read_to_end ↵kiseitai3-0/+40
trait methods
2025-06-05Clarify description of `Seek::stream_len`Tobias Bucher-1/+1
It can only describe the inner workings of the default implementation, other implementations might not be implemented using seeks at all.
2025-06-05Optimize `Seek::stream_len` impl for `File`Tobias Bucher-10/+14
It uses the file metadata on Unix with a fallback for files incorrectly reported as zero-sized. It uses `GetFileSizeEx` on Windows. This reduces the number of syscalls needed for determining the file size of an open file from 3 to 1.
2025-05-23Rollup merge of #141109 - oconnor663:pipe_example, r=Mark-SimulacrumMatthias Krüger-12/+26
discuss deadlocks in the std::io::pipe() example I think it's important to discuss deadlocks in examples of how to use pipes. The current example does include an explicit `drop()`, but it also implicitly relies on the fact that the `Command` object is temporary, so that it drops its copy of `pong_tx`. This sort of thing tends to trip people up when they use pipes for the first time. I might've gone overboard with the comments in this version, but I'm curious what folks think.
2025-05-19Add `std::io::Seek` instance for `std::io::Take`Mario Pastorelli-1/+172
2025-05-16discuss deadlocks in the std::io::pipe() exampleJack O'Connor-12/+26
2025-05-12update cfg(bootstrap)Pietro Albini-1/+1
2025-05-01Use present indicative tense in std::io::pipe() API docsEyal Kalderon-3/+3
The inline documentation for all other free functions in the `std::io` module use the phrase "creates a" instead of "create a", except for the currently nightly-only `std::io::pipe()` function. This commit updates the text to align with the predominant wording in the `std::io` module. I recognize this PR is quite a minuscule nitpick, so feel free to ignore and close if you disagree and/or there are bigger fish to fry. :smile:
2025-04-27use generic Atomic type where possibleChristopher Durham-2/+2
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-25Grammar fixes for BufRead::has_data_left docsEthan Wu-2/+2
2025-04-15Add warning comment to `Take::get_ref` and `Chain::get_ref`Josh Triplett-0/+8
The methods `Take::get_mut` and `Chain::get_mut` include comments warning about modifying the I/O state of the underlying reader. However, many readers (e.g. `File`) allow I/O using a shared reference (e.g. `&File`). So, add the same caveat to the `get_ref` methods.
2025-04-11rustdoc-search: add unbox flag to Result aliasesMichael Howell-0/+1
Fixes #139665
2025-04-09replace version placeholderBoxy-11/+11
2025-04-01io: Avoid Avoid marking bytes as uninit in `BufReader::peek`Benoît du Garreau-1/+0
2025-04-01io: Avoid marking buffer as uninit when copying to `BufWriter`Benoît du Garreau-1/+4
2025-03-28`io::Take`: avoid new `BorrowedBuf` creation in some caseBenoît du Garreau-4/+4
2025-03-23Auto merge of #136769 - thaliaarchi:io-optional-methods/stdio, r=joboetbors-28/+35
Provide optional `Read`/`Write` methods for stdio Override more of the default methods for `io::Read` and `io::Write` for stdio types, when efficient to do so, and deduplicate unsupported types. Tracked in https://github.com/rust-lang/rust/issues/136756. try-job: x86_64-msvc-1
2025-03-22Implement exact reads for StdinRawThalia Archibald-28/+35
2025-03-21Rollup merge of #138650 - thaliaarchi:io-write-fmt-known, r=ibraheemdevMatthias Krüger-35/+46
Optimize `io::Write::write_fmt` for constant strings When the formatting args to `fmt::Write::write_fmt` are a statically known string, it simplifies to only calling `write_str` without a runtime branch. Do the same in `io::Write::write_fmt` with `write_all`. Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-19Rollup merge of #137051 - thaliaarchi:io-optional-impls/empty, r=m-ou-seMatthias Krüger-11/+216
Implement default methods for `io::Empty` and `io::Sink` Implements default methods of `io::Read`, `io::BufRead`, and `io::Write` for `io::Empty` and `io::Sink`. These implementations are equivalent to the defaults, except in doing less unnecessary work. `Read::read_to_string` and `BufRead::read_line` both have a redundant call to `str::from_utf8` which can't be inlined from `core` and `Write::write_all_vectored` has slicing logic which can't be simplified (See on [Compiler Explorer](https://rust.godbolt.org/z/KK6xcrWr4)). The rest are optimized to the minimal with `-C opt-level=3`, but this PR gives that benefit to unoptimized builds. This includes an implementation of `Write::write_fmt` which just ignores the `fmt::Arguments<'_>`. This could be problematic whenever a user formatting impl is impure, but the docs do not guarantee that the args will be expanded. Tracked in https://github.com/rust-lang/rust/issues/136756. r? `@m-ou-se`
2025-03-19Rollup merge of #135394 - clarfonthey:uninit-slices-part-2, r=tgross35Matthias Krüger-2/+1
`MaybeUninit` inherent slice methods part 2 These were moved out of #129259 since they require additional libs-api approval. Tracking issue: #117428. New API surface: ```rust impl<T> [MaybeUninit<T>] { // replacing fill; renamed to avoid conflict pub fn write_filled(&mut self, value: T) -> &mut [T] where T: Clone; // replacing fill_with; renamed to avoid conflict pub fn write_with<F>(&mut self, value: F) -> &mut [T] where F: FnMut() -> T; // renamed to remove "fill" terminology, since this is closer to the write_*_of_slice methods pub fn write_iter<I>(&mut self, iter: I) -> (&mut [T], &mut Self) where I: Iterator<Item = T>; } ``` Relevant motivation for these methods; see #129259 for earlier methods' motiviations. * I chose `write_filled` since `filled` is being used as an object here, whereas it's being used as an action in `fill`. * I chose `write_with` instead of `write_filled_with` since it's shorter and still matches well. * I chose `write_iter` because it feels completely different from the fill methods, and still has the intent clear. In all of the methods, it felt appropriate to ensure that they contained `write` to clarify that they are effectively just special ways of doing `MaybeUninit::write` for each element of a slice. Tracking issue: https://github.com/rust-lang/rust/issues/117428 r? libs-api
2025-03-19Rollup merge of #136177 - hkBst:patch-24, r=ibraheemdevMatthias Krüger-24/+17
clarify BufRead::{fill_buf, consume} docs Fixes #85394
2025-03-18Apply suggestions from code reviewMarijn Schouten-7/+7
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-03-18Optimize io::Write::write_fmt for constant stringsThalia Archibald-35/+46
When the formatting args to `fmt::Write::write_fmt` are a statically known string, it simplifies to only calling `write_str` without a runtime branch. Do the same in `io::Write::write_fmt` with `write_all`. Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-17Rollup merge of #137793 - NobodyXu:stablise-annoymous-pipe, r=joshtriplettJacob Pratt-13/+35
Stablize anonymous pipe Since #135822 is staled, I create this PR to stablise anonymous pipe Closes #127154 try-job: test-various
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-14Mv os-specific trait impl of `Pipe*` into `std::os::*`Jiahao XU-0/+25
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-03-14Stablize feature `anonymous_pipe`Jiahao XU-13/+10
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-03-13Rollup merge of #138370 - cuviper:try_oom_error, r=jhprattMatthias Krüger-6/+10
Simulate OOM for the `try_oom_error` test We can create the expected error manually, rather than trying to produce a real one, so the error conversion test can run on all targets. Before, it was only running on 64-bit and not miri. In Fedora, we also found that s390x was not getting the expected error, "successfully" allocating the huge size because it was optimizing the real `malloc` call away. It's possible to counter that by looking at the pointer in any way, like a debug print, but it's more robust to just deal with errors directly, since this test is only about conversion. Related: #133806
2025-03-11Simulate OOM for the `try_oom_error` testJosh Stone-6/+10
We can create the expected error manually, rather than trying to produce a real one, so the error conversion test can run on all targets. Before, it was only running on 64-bit and not miri. In Fedora, we also found that s390x was not getting the expected error, "successfully" allocating the huge size because it was optimizing the real `malloc` call away. It's possible to counter that by looking at the pointer in any way, like a debug print, but it's more robust to just deal with errors directly, since this test is only about conversion.
2025-03-11Stabilize `std::io::ErrorKind::InvalidFilename`Pavel Grigorenko-2/+2
2025-03-10Implement default methods for io::Empty and io::SinkThalia Archibald-11/+216
Eliminate any redundant, unobservable logic from the their default method implementations. The observable changes are that `Write::write_fmt` for both types now ignores the formatting arguments, so a user fmt impl which has side effects is not invoked, and `Write::write_all_vectored` for both types does not advance the borrowed buffers. Neither behavior is guaranteed by the docs and the latter is documented as unspecified. `Empty` is not marked as vectored, so that `Chain<Empty, _>` and `Chain<_, Empty>` are not forced to be vectored.
2025-03-08Add inherent versions of MaybeUninit::fill methods for slicesltdk-2/+1
2025-03-07Auto merge of #138155 - matthiaskrgr:rollup-xq5buio, r=matthiaskrgrbors-1/+0
Rollup of 6 pull requests Successful merges: - #137674 (Enable `f16` for LoongArch) - #138034 (library: Use `size_of` from the prelude instead of imported) - #138060 (Revert #138019 after further discussion about how hir-pretty printing should work) - #138073 (Break critical edges in inline asm before code generation) - #138107 (`librustdoc`: clippy fixes) - #138111 (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`) r? `@ghost` `@rustbot` modify labels: rollup