summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2024-08-28allow BufReader::peek to be called on unsized typesbinarycat-0/+2
2024-08-07Rollup merge of #128406 - lolbinarycat:bufreader_peek, r=Mark-SimulacrumMatthias Krüger-0/+55
implement BufReader::peek Part of https://github.com/rust-lang/rust/issues/128405
2024-08-05implement BufReader::peekbinarycat-0/+55
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-4/+4
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-29Rollup merge of #109174 - soerenmeier:cursor_fns, r=dtolnayMatthias Krüger-32/+37
Replace `io::Cursor::{remaining_slice, is_empty}` This is a late follow up to the concerns raised in https://github.com/rust-lang/rust/issues/86369. https://github.com/rust-lang/rust/issues/86369#issuecomment-953096691 > This API seems focussed on the `Read` side of things. When `Seek`ing around and `Write`ing data, `is_empty` becomes confusing and `remaining_slice` is not very useful. When writing, the part of the slice before the cursor is much more interesting. Maybe we should have functions for both? Or a single function that returns both slices? (If we also have a `mut` version, a single function would be useful to allow mutable access to both sides at once.) New feature name: `cursor_remaining` > `cursor_split`. Added functions: ```rust fn split(&self) -> (&[u8], &[u8]); // fn before(&self) -> &[u8]; // fn after(&self) -> &[u8]; fn split_mut(&mut self) -> (&mut [u8], &mut [u8]); // fn before_mut(&mut self) -> &mut [u8]; // fn after_mut(&mut self) -> &mut [u8]; ``` A question was raised in https://github.com/rust-lang/rust/issues/86369#issuecomment-927124211 about whether to return a lifetime that would reflect the lifetime of the underlying bytes (`impl Cursor<&'a [u8]> { fn after(&self) -> &'a [u8] }`). The downside of doing this would be that it would not be possible to implement these functions generically over `T: AsRef<[u8]>`. ## Update Based on the review, before* and after* methods where removed.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-49/+35
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Replace `io::Cursor::{remaining_slice, is_empty}` with `io::Cursor::{split, ↵Sören Meier-32/+37
split_mut}`
2024-07-28Update CURRENT_RUSTC_VERSIONMark Rousskov-4/+4
2024-07-26Fix doc nitsJohn Arundel-36/+40
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-19Avoid ref when using format! for perfYuri Astrakhan-1/+1
Clean up a few minor refs in `format!` macro, as it has a tiny perf cost. A few more minor related cleanups.
2024-07-14std: Unsafe-wrap std::ioJubilee Young-9/+13
2024-07-14std: deny(unsafe_op_in_unsafe_fn) but allow sitesJubilee Young-0/+1
This provides a list of locations to hunt down issues in.
2024-07-13Rollup merge of #127659 - saethlin:manually-drop-bufwriter, r=joboetJubilee-7/+17
Use ManuallyDrop in BufWriter::into_parts The fact that `mem::forget` takes by value means that it interacts very poorly with Stacked Borrows; generally users think of calling it as a no-op, but in Stacked Borrows, the field retagging tends to cause surprise tag invalidation.
2024-07-12Use ManuallyDrop in BufWriter::into_partsBen Kimock-7/+17
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