about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2024-07-12Stabilize io_slice_advanceEduardo Sánchez Muñoz-12/+4
2024-07-02chore: remove duplicate wordshattizai-1/+1
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-06-11replace version placeholderPietro Albini-1/+1
2024-06-05Rollup merge of #126032 - ChrisDenton:update-docs, r=joboetMatthias Krüger-3/+2
Update description of the `IsTerminal` example The example code prompts for input if stdin is a terminal.
2024-06-05Update description of the `IsTerminal` exampleChris Denton-3/+2
2024-06-05Rollup merge of #123168 - joshtriplett:size-of-prelude, r=AmanieuJubilee-1/+0
Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude (Note: need to update the PR to add `align_of` and `align_of_val`, and remove the second commit with the myriad changes to appease the lint.) Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it.
2024-05-21Rollup merge of #125123 - a1phyr:fix-read_exact, r=workingjubileeMatthias Krüger-10/+55
Fix `read_exact` and `read_buf_exact` for `&[u8]` and `io:Cursor` - Drain after `read_exact` and `read_buf_exact` - Append to cursor in `read_buf_exact`
2024-05-20Address review commentsBenoît du Garreau-1/+33
2024-05-19Add example to IsTerminal::is_terminalMartijn-0/+34
2024-05-14Fix `read_exact` and `read_buf_exact` for `&[u8]` and `io:Cursor`Benoît du Garreau-10/+23
2024-05-13Rollup merge of #123817 - slanterns:seek_relative, r=dtolnayMatthias Krüger-2/+1
Stabilize `seek_seek_relative` This PR stabilizes `seek_seek_relative`: ```rust // std::io::Seek trait Seek { fn seek_relative(&mut self, offset: i64) -> Result<()>; } ``` <br> Tracking issue: https://github.com/rust-lang/rust/issues/117374. Implementation PR: https://github.com/rust-lang/rust/pull/116750. FCPs already completed in the tracking issue. Closes https://github.com/rust-lang/rust/issues/117374. r? libs-api
2024-05-13Add `size_of`, `size_of_val`, `align_of`, and `align_of_val` to the preludeJosh Triplett-1/+0
Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it. Add `size_of_val`, `align_of`, and `align_of_val` as well, with similar justification: widely useful, self-explanatory, unmistakeable for anything else, won't produce conflicts.
2024-05-11io::Write::write_fmt: panic if the formatter fails when the stream does not failRalf Jung-1/+5
2024-05-04Rollup merge of #122441 - a1phyr:improve_read_impls, r=ChrisDentonMatthias Krüger-10/+29
Improve several `Read` implementations - `read_to_end` and `read_to_string` for `Cursor` - Error on OOM in `read_to_string` of `&[u8]` and `VecDeque<u8>` - Avoid making the slices contiguous in `VecDeque::read_to_string` - ~`read_exact` and (unstable) `read_buf_exact` for `Take`~ - ~`read_buf` for `UnixStream` and `&UnixStream`~ (moved to #123084) - `read_to_end` for `ChildStdErr`
2024-05-03Rollup merge of #124412 - RalfJung:io-safety, r=AmanieuMatthias Krüger-1/+1
io safety: update Unix explanation to use `Arc` Fixes https://github.com/rust-lang/rust/issues/124384 Cc ```@jsgf```
2024-05-01Replace version placeholders for 1.79Mark Rousskov-7/+7
2024-04-27io safety: update Unix explanationRalf Jung-1/+1
2024-04-25Rollup merge of #124076 - NobodyXu:patch-1, r=dtolnayMichael Goulet-3/+1
Stablise io_error_downcast Tracking issue #99262 Closes #99262 FCP completed in https://github.com/rust-lang/rust/issues/99262#issuecomment-2077374397
2024-04-18Stablise io_error_downcastJiahao XU-3/+1
Tracking issue #99262
2024-04-17Stabilize `const_io_structs`Slanterns-6/+6
2024-04-15Auto merge of #123851 - NobodyXu:patch-1, r=BurntSushibors-6/+10
Update document for std::io::Error::downcast Resolve concern raised by `@BurntSushi` https://github.com/rust-lang/rust/issues/99262#issuecomment-2042641813
2024-04-15Update doc for std::io::Error::downcastJiahao XU-1/+5
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-12Update document for std::io::Error::downcastJiahao XU-6/+6
2024-04-12Avoid panicking branch in `append_to_string`Benoît du Garreau-1/+4
2024-04-12`VecDeque::read_to_string`: avoid making the slices contiguousBenoît du Garreau-9/+2
2024-04-12Improve several `Read` implementationsBenoît du Garreau-1/+24
2024-04-11Rollup merge of #123806 - joboet:advanced_overflow, r=AmanieuMatthias Krüger-0/+9
Panic on overflow in `BorrowedCursor::advance` Passing `usize::MAX` to `advance` clearly isn't correct, but the current assertion fails to detect this when overflow checks are disabled. This isn't unsound, but should probably be fixed regardless.
2024-04-11Rollup merge of #122882 - Zoxc:panic-output-panic, r=AmanieuMatthias Krüger-5/+25
Avoid a panic in `set_output_capture` in the default panic handler This avoid a panic in the default panic handler by not using `set_output_capture` as `OUTPUT_CAPTURE.with` may panic once `OUTPUT_CAPTURE` is dropped. A new non-panicking `try_set_output_capture` variant of `set_output_capture` is added for use in the default panic handler.
2024-04-12Stabilize `Seek::seek_relative`Slanterns-2/+1
2024-04-11core: panic on overflow in `BorrowedCursor`joboet-0/+9
2024-04-11Factor some common `io::Error` constantsBenoît du Garreau-51/+36
2024-04-10Auto merge of #122393 - a1phyr:specialize_read_buf_exact, r=joboetbors-18/+74
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-22Avoid a panic in `set_output_capture` in the default panic handlerJohn Kåre Alsaker-5/+25
2024-03-20Auto merge of #122754 - Mark-Simulacrum:bootstrap-bump, r=albertlarsan68bors-2/+2
Bump to 1.78 bootstrap compiler https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-03-19branch 1.78: replace-version-placeholderMark Rousskov-2/+2
2024-03-20resolve clippy errorsonur-ozkan-4/+3
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-14Fix minor documentation issue. Code outside the test would fail. Seek ↵baitcode-0/+2
documentation clearly states that negative indexes will cause error. Just making the code in the example to return Result::Ok, instead of Result::Error.
2024-03-12Specialize many implementations of `Read::read_buf_exact`Benoît du Garreau-18/+74
2024-03-10Rollup merge of #122276 - RalfJung:io-read, r=NilstriebMatthias Krüger-10/+7
io::Read trait: make it more clear when we are adressing implementations vs callers Inspired by [this](https://github.com/rust-lang/rust/issues/72186#issuecomment-1987076295) comment. For some reason we only have that `buf` warning in `read` and `read_exact`, even though it affects a bunch of other functions of this trait as well. It doesn't seem worth copy-pasting the same text everywhere though so I did not change this.
2024-03-10io::Read trait: make it more clear when we are adressing implementations vs ↵Ralf Jung-10/+7
callers
2024-03-10disable OOM test in MiriRalf Jung-0/+2
2024-03-09Rollup merge of #121403 - kornelski:io-oom, r=dtolnayGuillaume Boisseau-5/+27
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-09Rollup merge of #99153 - Dajamante:issue/95622, r=dtolnayGuillaume Boisseau-0/+26
Add Read Impl for &Stdin r? `@oli-obk` fixes #95622
2024-03-03Fix quadratic behavior of repeated vectored writesJan Verbeek-31/+50
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-03-01Auto merge of #114016 - krtab:delete_sys_memchr, r=workingjubileebors-2/+2
Delete architecture-specific memchr code in std::sys 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. The interest of putting architecture specific code back in core is linked to the discussion to be had in #113654
2024-02-29Rollup merge of #110543 - joboet:reentrant_lock, r=m-ou-seMatthias Krüger-10/+35
Make `ReentrantLock` public Implements the ACP rust-lang/libs-team#193. ``@rustbot`` label +T-libs-api +S-waiting-on-ACP
2024-02-26Fill in Read::read_buf for &StdinDavid Tolnay-0/+3
2024-02-26Fix stable feature name and stabilization version of Read for &StdinDavid Tolnay-1/+1