about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2022-07-24Allow Buffer methods to inlineBen Kimock-0/+9
2022-07-24Remove some redundant checks from BufReaderBen Kimock-53/+106
The implementation of BufReader contains a lot of redundant checks. While any one of these checks is not particularly expensive to execute, especially when taken together they dramatically inhibit LLVM's ability to make subsequent optimizations.
2022-07-23Remove `mut`Phosra-1/+1
2022-07-16Rollup merge of #98387 - NobodyXu:feature/std_io_Error_try_downgrade_inner, ↵Yuki Okushi-1/+127
r=yaahc Add new unstable API `downcast` to `std::io::Error` https://github.com/rust-lang/libs-team/issues/57 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-07-15Apply suggestions from code reviewJane Losare-Lusby-1/+1
2022-07-15Improve example of `downcast`Jiahao XU-3/+4
Co-authored-by: Jane Losare-Lusby <jlusby42@gmail.com>
2022-07-14Rename `std::io::Error::try_downcast_inner` to `downcast`Jiahao XU-11/+11
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-07-05Add `BufRead::skip_until`William Venner-0/+84
2022-06-28Follow C-RW-VALUE in std::io::Cursor exampleMatt Fellenz-1/+1
2022-06-28Auto merge of #98324 - conradludgate:write-vectored-vec, r=Mark-Simulacrumbors-25/+149
attempt to optimise vectored write benchmarked: old: ``` test io::cursor::tests::bench_write_vec ... bench: 68 ns/iter (+/- 2) test io::cursor::tests::bench_write_vec_vectored ... bench: 913 ns/iter (+/- 31) ``` new: ``` test io::cursor::tests::bench_write_vec ... bench: 64 ns/iter (+/- 0) test io::cursor::tests::bench_write_vec_vectored ... bench: 747 ns/iter (+/- 27) ``` More unsafe than I wanted (and less gains) in the end, but it still does the job
2022-06-26attempt to optimise vectored writeConrad Ludgate-25/+149
2022-06-23Rollup merge of #96173 - jmaargh:jmaargh/with-capacity-doc-fix, r=Dylan-DPCMichael Goulet-4/+4
Fix documentation for `with_capacity` and `reserve` families of methods Fixes #95614 Documentation for the following methods - `with_capacity` - `with_capacity_in` - `with_capacity_and_hasher` - `reserve` - `reserve_exact` - `try_reserve` - `try_reserve_exact` was inconsistent and often not entirely correct where they existed on the following types - `Vec` - `VecDeque` - `String` - `OsString` - `PathBuf` - `BinaryHeap` - `HashSet` - `HashMap` - `BufWriter` - `LineWriter` since the allocator is allowed to allocate more than the requested capacity in all such cases, and will frequently "allocate" much more in the case of zero-sized types (I also checked `BufReader`, but there the docs appear to be accurate as it appears to actually allocate the exact capacity). Some effort was made to make the documentation more consistent between types as well.
2022-06-23Use `unwrap` instead of `unwrap_unchecked`Jiahao XU-3/+7
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Add new unit test `test_try_downcast_inner`Jiahao XU-1/+52
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Add new unstable API `Error::try_downgrade_inner`Jiahao XU-0/+57
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Impl `io::error::repr_bitpacked::Repr::new`Jiahao XU-0/+9
that accepts `ErrorData<Box<Custom>>` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Impl `io::error::repr_unpacked::Repr::new`Jiahao XU-0/+4
that accepts `ErrorData<Box<Custom>>` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-21update ioslice docs to use shared slicesConrad Ludgate-6/+6
2022-06-20Rollup merge of #94855 - m-ou-se:advance-slice-panic-docs, r=kennytmDylan DPC-20/+38
Panic when advance_slices()'ing too far and update docs. This updates advance_slices() to panic when advancing too far, like advance() already does. And updates the docs to say so. See https://github.com/rust-lang/rust/issues/62726#issuecomment-1065253213
2022-06-19Fix documentation for with_capacity and reserve families of methodsjmaargh-4/+4
Documentation for the following methods with_capacity with_capacity_in with_capacity_and_hasher reserve reserve_exact try_reserve try_reserve_exact was inconsistent and often not entirely correct where they existed on the following types Vec VecDeque String OsString PathBuf BinaryHeap HashSet HashMap BufWriter LineWriter since the allocator is allowed to allocate more than the requested capacity in all such cases, and will frequently "allocate" much more in the case of zero-sized types (I also checked BufReader, but there the docs appear to be accurate as it appears to actually allocate the exact capacity). Some effort was made to make the documentation more consistent between types as well. Fix with_capacity* methods for Vec Fix *reserve* methods for Vec Fix docs for *reserve* methods of VecDeque Fix docs for String::with_capacity Fix docs for *reserve* methods of String Fix docs for OsString::with_capacity Fix docs for *reserve* methods on OsString Fix docs for with_capacity* methods on HashSet Fix docs for *reserve methods of HashSet Fix docs for with_capacity* methods of HashMap Fix docs for *reserve methods on HashMap Fix expect messages about OOM in doctests Fix docs for BinaryHeap::with_capacity Fix docs for *reserve* methods of BinaryHeap Fix typos Fix docs for with_capacity on BufWriter and LineWriter Fix consistent use of `hasher` between `HashMap` and `HashSet` Fix warning in doc test Add test for capacity of vec with ZST Fix doc test error
2022-06-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-5/+4
2022-06-10Rollup merge of #97922 - paolobarbolini:no-vecdeque-extra-reserve, r=the8472Yuki Okushi-2/+0
Remove redundant calls to reserve in impl Write for VecDeque Removes the reserve calls made redundant by #95904 (as discussed in https://github.com/rust-lang/rust/pull/95632#discussion_r846850293)
2022-06-10Auto merge of #95770 - nrc:read-buf-builder, r=joshtriplettbors-7/+11
std::io: Modify some ReadBuf method signatures to return `&mut Self` This allows using `ReadBuf` in a builder-like style and to setup a `ReadBuf` and pass it to `read_buf` in a single expression, e.g., ``` // With this PR: reader.read_buf(ReadBuf::uninit(buf).assume_init(init_len))?; // Previously: let mut buf = ReadBuf::uninit(buf); buf.assume_init(init_len); reader.read_buf(&mut buf)?; ``` r? `@sfackler` cc https://github.com/rust-lang/rust/issues/78485, https://github.com/rust-lang/rust/issues/94741
2022-06-09Remove redundant calls to reserve in impl Write for VecDequePaolo Barbolini-2/+0
2022-06-09Rollup merge of #95632 - evanrichter:master, r=joshtriplettYuki Okushi-0/+48
impl Read and Write for VecDeque<u8> Implementing `Read` and `Write` for `VecDeque<u8>` fills in the VecDeque api surface where `Vec<u8>` and `Cursor<Vec<u8>>` already impl Read and Write. Not only for completeness, but VecDeque in particular is a very handy mock interface for a TCP echo service, if only it supported Read/Write. Since this PR is just an impl trait, I don't think there is a way to limit it behind a feature flag, so it's "insta-stable". Please correct me if I'm wrong here, not trying to rush stability.
2022-05-29protect `std::io::Take::limit` from overflow in `read`Frank King-0/+20
fixs #94981
2022-05-29Use Box::new() instead of box syntax in std testsest31-3/+3
2022-05-19impl Read and Write for VecDeque<u8>Evan Richter-0/+48
* For read and read_buf, only the front slice of a discontiguous VecDeque is copied. The VecDeque is advanced after reading, making any back slice available for reading with a second call to Read::read(_buf). * For write, the VecDeque always appends the entire slice to the end, growing its allocation when necessary.
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-3/+0
2022-05-03std::io: Modify some ReadBuf method signatures to return `&mut Self`Nick Cameron-7/+11
This allows using `ReadBuf` in a builder-like style and to setup a `ReadBuf` and pass it to `read_buf` in a single expression, e.g., ``` // With this PR: reader.read_buf(ReadBuf::uninit(buf).assume_init(init_len))?; // Previously: let mut buf = ReadBuf::uninit(buf); buf.assume_init(init_len); reader.read_buf(&mut buf)?; ``` Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-04-07Rollup merge of #95185 - m-ou-se:stabilize-stdin-lines, r=Mark-SimulacrumDylan DPC-2/+1
Stabilize Stdin::lines. Closes https://github.com/rust-lang/rust/issues/87096 Fcp completed here: https://github.com/rust-lang/rust/issues/87096#issuecomment-1028792980
2022-04-06Bump stabilization of stdin_forwarders to 1.62.0.Mara Bos-1/+1
2022-03-30Auto merge of #95241 - Gankra:cleaned-provenance, r=workingjubileebors-5/+5
Strict Provenance MVP This patch series examines the question: how bad would it be if we adopted an extremely strict pointer provenance model that completely banished all int<->ptr casts. The key insight to making this approach even *vaguely* pallatable is the ptr.with_addr(addr) -> ptr function, which takes a pointer and an address and creates a new pointer with that address and the provenance of the input pointer. In this way the "chain of custody" is completely and dynamically restored, making the model suitable even for dynamic checkers like CHERI and Miri. This is not a formal model, but lots of the docs discussing the model have been updated to try to the *concept* of this design in the hopes that it can be iterated on. See #95228
2022-03-30Rollup merge of #95294 - sourcefrog:doc-copy, r=dtolnayDylan DPC-0/+10
Document Linux kernel handoff in std::io::copy and std::fs::copy
2022-03-29Warn that platform-specific behavior may changeMartin Pool-0/+4
2022-03-29cleanup some of the less terrifying library codeAria Beingessner-1/+1
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-5/+5
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.
2022-03-29Indicate the correct error code in the `compile_fail` block.Thom Chiovoloni-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-03-24Document Linux kernel handoff in std::io::copy and std::fs::copyMartin Pool-0/+6
2022-03-23Add a `compile_fail` doctest to check that `io::Error: !UnwindSafe`Thom Chiovoloni-0/+9
2022-03-23Ensure io::Error's bitpacked repr doesn't accidentally impl UnwindSafeThom Chiovoloni-5/+6
2022-03-21Stabilize Stdin::lines.Mara Bos-2/+1
2022-03-19Rollup merge of #93263 - sunfishcode:sunfishcode/detatched-console-handle, ↵Dylan DPC-9/+70
r=dtolnay Consistently present absent stdio handles on Windows as NULL handles. This addresses #90964 by making the std API consistent about presenting absent stdio handles on Windows as NULL handles. Stdio handles may be absent due to `#![windows_subsystem = "windows"]`, due to the console being detached, or due to a child process having been launched from a parent where stdio handles are absent. Specifically, this fixes the case of child processes of parents with absent stdio, which previously ended up with `stdin().as_raw_handle()` returning `INVALID_HANDLE_VALUE`, which was surprising, and which overlapped with an unrelated valid handle value. With this patch, `stdin().as_raw_handle()` now returns null in these situation, which is consistent with what it does in the parent process. And, document this in the "Windows Portability Considerations" sections of the relevant documentation.
2022-03-19Rollup merge of #92663 - cuviper:generic-write-cursor, r=dtolnayDylan DPC-51/+86
Implement `Write for Cursor<[u8; N]>`, plus `A: Allocator` cursor support This implements `Write for Cursor<[u8; N]>`, and also adds support for generic `A: Allocator` in `Box` and `Vec` cursors. This was inspired by a user questioning why they couldn't write a `Cursor<[u8; N]>`: https://users.rust-lang.org/t/why-vec-and-not-u8-makes-cursor-have-write/68210 Related history: - #27197 switched `AsRef<[u8]>` for reading and seeking - #67415 tried to use `AsMut<[u8]>` for writing, but did not specialize `Vec`.
2022-03-18Bump impl Write for Cursor<[u8; N]> to 1.61David Tolnay-1/+1
2022-03-16changed wordingDylan DPC-1/+2
2022-03-15Improve the explanation about the behaviour of read_linezed.zy-1/+1
2022-03-11Update tests.Mara Bos-4/+4
2022-03-11Update advance and advance_slices docs.Mara Bos-14/+28
2022-03-11Panic when advance_slices()'ing too far.Mara Bos-2/+6