summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2021-06-07Forwarding implementation for Seek trait's stream_position methodmyshylin-0/+10
2021-05-24remove cfg(bootstrap)Pietro Albini-4/+2
2021-05-23Rollup merge of #85288 - Geal:clarify-std-io-read, r=dtolnayDylan DPC-1/+7
add an example to explain std::io::Read::read returning 0 in some cases I have always found the explanation about `Read::read` returning 0 to indicate EOF but not indefinitely, so here's more info using Linux as example. I can also add example code if necessary
2021-05-20Rollup merge of #85275 - CDirkx:memchr, r=m-ou-seGuillaume Gomez-2/+2
Move `std::memchr` to `sys_common` `std::memchr` is a thin abstraction over the different `memchr` implementations in `sys`, along with documentation and tests. The module is only used internally by `std`, nothing is exported externally. Code like this is exactly what the `sys_common` module is for, so this PR moves it there.
2021-05-19Auto merge of #85176 - a1phyr:impl_clone_from, r=yaahcbors-1/+18
Override `clone_from` for some types Override `clone_from` method of the `Clone` trait for: - `cell::RefCell` - `cmp::Reverse` - `io::Cursor` - `mem::ManuallyDrop` This can bring performance improvements.
2021-05-18fix typoJorge Ferreira-2/+2
2021-05-14add an example to explain std::io::Read::read returning 0 in some casesGeoffroy Couprie-1/+7
the example focuses on Linux, but that should be enough to explain how the behaviour can change
2021-05-14Move `std::memchr` to `sys_common`Christiaan Dirkx-2/+2
2021-05-11Override `clone_from` for some typesBenoît du Garreau-1/+18
2021-05-10io::Seek::rewind: Set tracking issueIan Jackson-1/+1
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10Fix typo in docIan Jackson-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-10io::Seek: Provide rewind()Ian Jackson-0/+35
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10io::Seek: Mention that seeking can fail due to buffer flush failIan Jackson-0/+2
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-06Auto merge of #79930 - tgnottingham:bufwriter_performance, r=m-ou-sebors-39/+178
Optimize BufWriter
2021-05-03Correct stability of ErrorKind::OutOfMemoryKornel-1/+1
2021-05-02Add ErrorKind::OutOfMemoryKornel-0/+6
2021-04-22Rework `at_exit` to `cleanup`Christiaan Dirkx-23/+22
2021-04-21Replace all `fmt.pad` with `debug_struct`Christiaan Dirkx-9/+9
2021-04-18Bump to 1.53.0CDirkx-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-04-18Rename `NotSupported` to `Unsupported`Christiaan Dirkx-4/+6
2021-04-18Bump since to 1.52.0CDirkx-1/+1
2021-04-18Add and insta-stabilize `std::io::ErrorKind::NotSupported`Christiaan Dirkx-0/+5
2021-04-13BufWriter: improve safety commentTyson Nottingham-6/+10
2021-04-13BufWriter: simplify buffer drainingTyson Nottingham-5/+1
2021-04-13BufWriter: use #[cold] and less aggressive #[inline] hintsTyson Nottingham-1/+3
2021-04-13BufWriter: handle possibility of overflowTyson Nottingham-15/+39
2021-04-13BufWriter: optimize for write sizes less than buffer sizeTyson Nottingham-24/+32
Optimize for the common case where the input write size is less than the buffer size. This slightly increases the cost for pathological write patterns that commonly fill the buffer exactly, but if a client is doing that frequently, they're already paying the cost of frequent flushing, etc., so the cost is of this optimization to them is relatively small.
2021-04-13BufWriter: avoid using expensive Vec methodsTyson Nottingham-12/+75
We use a Vec as our internal, constant-sized buffer, but the overhead of using methods like `extend_from_slice` can be enormous, likely because they don't get inlined, because `Vec` has to repeat bounds checks that we've already done, and because it makes considerations for things like reallocating, even though they should never happen.
2021-04-13BufWriter: apply #[inline] / #[inline(never)] optimizationsTyson Nottingham-24/+66
Ensure that `write` and `write_all` can be inlined and that their commonly executed fast paths can be as short as possible. `write_vectored` would likely benefit from the same optimization, but I omitted it because its implementation is more complex, and I don't have a benchmark on hand to guide its optimization.
2021-04-13Auto merge of #82992 - philippeitis:stabilize_bufreader_seek_relative, ↵bors-1/+1
r=workingjubilee Stabilize `bufreader_seek_relative` This PR marks `BufReader::seek_relative` as stable - the associated issue, #31100, has passed the final comment period without any issues, and from what I understand, the only thing left to stabilize this is to submit a PR marking the method as stable. Closes #31100.
2021-04-02Auto merge of #80965 - camelid:rename-doc-spotlight, r=jyn514bors-2/+4
Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` Fixes #80936. "spotlight" is not a very specific or self-explaining name. Additionally, the dialog that it triggers is called "Notable traits". So, "notable trait" is a better name. * Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` * Rename `#![feature(doc_spotlight)]` to `#![feature(doc_notable_trait)]` * Update documentation * Improve documentation r? `@Manishearth`
2021-03-27Rollup merge of #83555 - m-ou-se:inline-io-error-new-const, r=jackh726Dylan DPC-0/+8
Add #[inline] to io::Error methods Fixes #82812
2021-03-28Rollup merge of #83560 - m-ou-se:io-chain-debug, r=sfacklerYuki Okushi-7/+1
Derive Debug for io::Chain instead of manually implementing it. This derives Debug for io::Chain instead of manually implementing it. The manual implementation has the same bounds, so I don't think there's any reason for a manual implementation. The names used in the derive implementation are even nicer (`first`/`second`) than the manual implementation (`t`/`u`), and include the `done_first` field too.
2021-03-27Derive Debug for io::Chain instead of manually implementing it.Mara Bos-7/+1
The manual implementation has the same bounds, so I don't think there's any reason for a manual implementation. The names used in the derive implementation are even nicer (`first`/`second`) than the manual implementation (`t`/`u`), and include the `done_first` field too.
2021-03-27Use DebugStruct::finish_non_exhaustive() in std.Mara Bos-1/+1
2021-03-27Add #[inline] to io::Error methods.Mara Bos-0/+8
2021-03-24Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisaDylan DPC-15/+63
Add internal io::Error::new_const to avoid allocations. This makes it possible to have a io::Error containing a message with zero allocations, and uses that everywhere to avoid the *three* allocations involved in `io::Error::new(kind, "message")`. The function signature isn't perfect, because it needs a reference to the `&str`. So for now, this is just a `pub(crate)` function. Later, we'll be able to use `fn new_const<MSG: &'static str>(kind: ErrorKind)` to make that a bit better. (Then we'll also be able to use some ZST trickery if that would result in more efficient code.) See https://github.com/rust-lang/rust/issues/83352
2021-03-21Bump stable version of bufreader_seek_relative.Mara Bos-1/+1
2021-03-21Fix typosMara Bos-2/+2
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-15/+21
2021-03-21Add test for io::Error::new_const.Mara Bos-0/+10
2021-03-21Add internal io::Error::new_const tot avoid allocations.Mara Bos-0/+26
2021-03-21Add test for io::Error's size.Mara Bos-0/+6
2021-03-19Rollup merge of #82892 - jix:clarify-read-read, r=joshtriplettDylan DPC-2/+7
Clarify docs for Read::read's return value Right now the docs for `Read::read`'s return value are phrased in a way that makes it easy for the reader to assume that the return value is never larger than the passed buffer. This PR clarifies that this is a requirement for implementations of the trait, but that callers have to expect a buggy yet safe implementation failing to do so, especially if unchecked accesses to the buffer are done afterwards. I fell into this trap recently, and when I noticed, I looked at the docs again and had the feeling that I might not have been the first one to miss this. The same issue of trusting the return value of `read` was also present in std itself for about 2.5 years and only fixed recently, see #80895. I hope that clarifying the docs might help others to avoid this issue.
2021-03-18Clarify docs for Read::read's return valueJannis Harder-2/+7
2021-03-15Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]`Camelid-2/+4
"spotlight" is not a very specific or self-explaining name. Additionally, the dialog that it triggers is called "Notable traits". So, "notable trait" is a better name. * Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` * Rename `#![feature(doc_spotlight)]` to `#![feature(doc_notable_trait)]` * Update documentation * Improve documentation
2021-03-10Stabilize `bufreader_seek_relative`philippeitis-1/+1
2021-03-07Generalize Write impl for Vec<u8> to Vec<u8, A>Joel Höner-1/+2
As discussed in the issue tracker for the wg-allocators working group[1], updating this implementation for allocator support was most likely just forgotten in the original PR. [1]: https://github.com/rust-lang/wg-allocators/issues/86
2021-03-05Rollup merge of #82728 - calebsander:refactor/bufreader-buf, r=m-ou-seMara-4/+3
Avoid unnecessary Vec construction in BufReader As mentioned in #80460, creating a `Vec` and calling `Vec::into_boxed_slice()` emits unnecessary calls to `realloc()` and `free()`. Updated the code to use `Box::new_uninit_slice()` to create a boxed slice directly. I think this also makes it more explicit that the initial contents of the buffer are uninitialized. r? ``@m-ou-se``
2021-03-05Rollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertjMara-3/+103
Improved IO Bytes Size Hint After trying to implement better `size_hint()` return values for `File` in [this PR](https://github.com/rust-lang/rust/pull/81044) and changing to implementing it for `BufReader` in [this PR](https://github.com/rust-lang/rust/pull/81052), I have arrived at this implementation that provides tighter bounds for the `Bytes` iterator of various readers including `BufReader`, `Empty`, and `Chain`. Unfortunately, for `BufReader`, the size_hint only improves after calling `fill_buffer` due to it using the contents of the buffer for the hint. Nevertheless, the the tighter bounds should result in better pre-allocation of space to handle the contents of the `Bytes` iterator. Closes #81052