about summary refs log tree commit diff
path: root/library/std/src/io/mod.rs
AgeCommit message (Collapse)AuthorLines
2025-01-26Move `std::io::pipe` code into its own fileTobias Bucher-255/+3
2025-01-25Improve and expand documentation of pipesJosh Triplett-8/+14
- Simplify some of the language - Minor grammar fixes - Don't imply that pipes *only* work across multiple processes; instead, *suggest* that they're typically used across two or more separate processes. - Specify that portable applications cannot use multiple readers or multiple writers for messages larger than a byte, due to potential interleaving. - Remove no-longer-referenced footnote URLs.
2025-01-17Move `std::pipe::*` into `std::io`Jiahao XU-0/+249
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2024-12-21Less unwrap() in documentationKornel-10/+15
2024-11-25std: expose `const_io_error!` as `const_error!`joboet-2/+5
ACP: rust-lang/libs-team#205 Tracking issue: #133448
2024-11-09Add as_slice/into_slice for IoSlice/IoSliceMut.Alona Enraght-Moony-0/+45
Co-authored-by: Mike Pedersen <mike@mikepedersen.dk> Co-authored-by: Nathan West <Lucretiel@gmail.com>
2024-10-15replace placeholder versionJosh Stone-1/+1
(cherry picked from commit 567fd9610cbfd220844443487059335d7e1ff021)
2024-10-04Stabilize `BufRead::skip_until`okaneco-3/+1
2024-09-23Add a comment to `Read::read_buf`Benoît du Garreau-0/+2
2024-09-23Fix `io::default_read_to_end` uses of `read_buf`Benoît du Garreau-10/+14
2024-09-23Fix `io::Take::read_buf`Benoît du Garreau-4/+5
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-09-21wait for two short reads before uncapping the max read sizeThe 8472-3/+13
for disk IO: 1st short read = probably at end of file 2nd short read = confirming that it's indeed EOF
2024-09-20[Clippy] Remove final std paths for diagnostic itemGnomedDev-0/+1
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-29Reformat `use` declarations.Nicholas Nethercote-11/+7
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Update CURRENT_RUSTC_VERSIONMark Rousskov-4/+4
2024-07-26Fix doc nitsJohn Arundel-13/+13
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/+2
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-12Stabilize io_slice_advanceEduardo Sánchez Muñoz-12/+4
2024-06-11replace version placeholderPietro Albini-1/+1
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-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-1/+4
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-04-27io safety: update Unix explanationRalf Jung-1/+1
2024-04-12Avoid panicking branch in `append_to_string`Benoît du Garreau-1/+4
2024-04-11Rollup merge of #122882 - Zoxc:panic-output-panic, r=AmanieuMatthias Krüger-3/+3
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-11Factor some common `io::Error` constantsBenoît du Garreau-23/+5
2024-03-22Avoid a panic in `set_output_capture` in the default panic handlerJohn Kåre Alsaker-3/+3
2024-03-12Specialize many implementations of `Read::read_buf_exact`Benoît du Garreau-18/+25
2024-03-10io::Read trait: make it more clear when we are adressing implementations vs ↵Ralf Jung-10/+7
callers
2024-03-09Rollup merge of #121403 - kornelski:io-oom, r=dtolnayGuillaume Boisseau-2/+2
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-02-21Remove unnecessary map_errKornel-2/+2
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-19Auto merge of #105917 - a1phyr:read_chain_more_impls, r=workingjubileebors-3/+55
Specialize some methods of `io::Chain` This PR specializes the implementation of some methods of `io::Chain`, which could bring performance improvements when using it.
2024-02-07Make `io::BorrowedCursor::advance` safeBenoît du Garreau-10/+2
This also keeps the old `advance` method under `advance_unchecked` name. This makes pattern like `std::io::default_read_buf` safe to write.
2024-02-05Rollup merge of #120607 - conradludgate:fix-120603, r=dtolnayMatthias Krüger-1/+6
fix #120603 by adding a check in default_read_buf Fixes #120603 by checking the returned read n is in-bounds of the cursor. Interestingly, I noticed that `BorrowedBuf` side-steps this issue by using checked accesses. Maybe this can be switched to unchecked to mirror what BufReader does https://github.com/rust-lang/rust/blob/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/core/src/io/borrowed_buf.rs#L95
2024-02-03fix #120603 by adding a check in default_read_bufConrad Ludgate-1/+6
2024-01-31Improve `io::Read::read_buf_exact` error caseBenoît du Garreau-1/+4
- Use `const_io_error` instead of `Error::new` - Use the same message as `read_exact`
2024-01-29Handle out of memory errors in io:Read::read_to_end()Kornel-1/+37
2023-11-28Rollup merge of #118222 - the8472:copy-use-vec-write, r=m-ou-seMatthias Krüger-37/+81
unify read_to_end and io::copy impls for reading into a Vec This ports over the initial probe (to avoid allocation) and the dynamic read sizing from the io::copy specialization to the `default_read_to_end` implementation which already had its own optimizations for different cases. I think it should be a best-of-both now. suggested by `@a1phyr` in https://github.com/rust-lang/rust/pull/117576#issuecomment-1803408492
2023-11-26unify read_to_end and io::copy impls for reading into a VecThe 8472-37/+81
2023-11-24Rollup merge of #116807 - seanlinsley:patch-2, r=thomccMatthias Krüger-0/+4
Improve rewind documentation The persistent use of an internal cursor for readers is expected for buffer data types that aren't read all at once, but for files it leads to the confusing situation where calling `read_to_end` on the same file handle multiple times only returns the contents of the file for the first call. This PR adds a note to the documentation clarifying that in that case, `rewind()` must first be called. I'm unsure if this is the right location for the docs update. Maybe it should also be duplicated on `File`?
2023-11-23Auto merge of #98943 - WilliamVenner:feat/bufread_skip_until, r=dtolnaybors-0/+84
Add `BufRead::skip_until` Alternative version of `BufRead::read_until` that simply discards data, rather than copying it into a buffer. Useful for situations like skipping irrelevant data in a binary file format that is NUL-terminated. <details> <summary>Benchmark</summary> ``` running 2 tests test bench_read_until ... bench: 123 ns/iter (+/- 6) test bench_skip_until ... bench: 66 ns/iter (+/- 3) ``` ```rs #![feature(test)] extern crate test; use test::Bencher; use std::io::{ErrorKind, BufRead}; fn skip_until<R: BufRead + ?Sized>(r: &mut R, delim: u8) -> Result<usize, std::io::Error> { let mut read = 0; loop { let (done, used) = { let available = match r.fill_buf() { Ok(n) => n, Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, Err(e) => return Err(e), }; match memchr::memchr(delim, available) { Some(i) => (true, i + 1), None => (false, available.len()), } }; r.consume(used); read += used; if done || used == 0 { return Ok(read); } } } const STR: &[u8] = b"Ferris\0Hello, world!\0"; #[bench] fn bench_skip_until(b: &mut Bencher) { b.iter(|| { let mut io = std::io::Cursor::new(test::black_box(STR)); skip_until(&mut io, b'\0').unwrap(); let mut hello = Vec::with_capacity(b"Hello, world!\0".len()); let num_bytes = io.read_until(b'\0', &mut hello).unwrap(); assert_eq!(num_bytes, b"Hello, world!\0".len()); assert_eq!(hello, b"Hello, world!\0"); }); } #[bench] fn bench_read_until(b: &mut Bencher) { b.iter(|| { let mut io = std::io::Cursor::new(test::black_box(STR)); io.read_until(b'\0', &mut Vec::new()).unwrap(); let mut hello = Vec::with_capacity(b"Hello, world!\0".len()); let num_bytes = io.read_until(b'\0', &mut hello).unwrap(); assert_eq!(num_bytes, b"Hello, world!\0".len()); assert_eq!(hello, b"Hello, world!\0"); }); } ``` </details>
2023-11-19Rollup merge of #116750 - fintelia:seek_seek_relative, r=Mark-SimulacrumTakayuki Maeda-0/+30
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-11-09Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`John Millikin-2/+1
Assigned new feature name `core_io_borrowed_buf` to distinguish from the `Read::read_buf` functionality in `std::io`.
2023-11-04Improve documentationJonathan Behrens-1/+5
2023-10-29Add tracking issueJonathan Behrens-1/+1