about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
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-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-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-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
2021-03-03Avoid unnecessary Vec construction in BufReaderCaleb Sander-4/+3
2021-03-02Rollup merge of #80189 - jyn514:convert-primitives, r=poliorceticsYuki Okushi-2/+1
Convert primitives in the standard library to intra-doc links Blocked on https://github.com/rust-lang/rust/pull/80181. I forgot that this needs to wait for the beta bump so the standard library can be documented with `doc --stage 0`. Notably I didn't convert `core::slice` because it's like 50 links and I got scared :fearful:
2021-02-27Rollup merge of #82395 - pickfire:see-more, r=GuillaumeGomezDylan DPC-2/+2
Add missing "see its documentation for more" stdio StdoutLock and StderrLock does not have example, it would be better to leave "see its documentation for more" like iter docs.
2021-02-25Convert primitives to use intra-doc linksJoshua Nelson-2/+1
2021-02-24library: Normalize safety-for-unsafe-block commentsMiguel Ojeda-1/+1
Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-22Add missing "see its documentation for more" stdioIvan Tham-2/+2
StdoutLock and StderrLock does not have example, it would be better to leave "see its documentation for more" like iter docs.
2021-02-20Rollup merge of #82244 - pickfire:patch-6, r=dtolnayGuillaume Gomez-2/+2
Keep consistency in example for Stdin StdinLock Stdin uses handle whereas StdinLock uses stdin_lock, changed it to handle.
2021-02-18Keep consistency in example for Stdin StdinLockIvan Tham-2/+2
Stdin uses handle whereas StdinLock uses stdin_lock, changed it to handle.
2021-02-18Add missing link from stdio docIvan Tham-4/+4
2021-01-31specialize io::copy to use the memory of the writer if it is a BufWriterThe8472-8/+136
2021-01-31Fix line length formatXavientois-1/+3
2021-01-31Fix formatting on modXavientois-2/+1
2021-01-31Add space for proper indentationXavientois-1/+1
2021-01-31Remove trailing newlineXavientois-2/+3
2021-01-31Add tests for SizeHint implementationsXavientois-2/+29
2021-01-31Implement SizeHint trait for BufReader, Emtpy, and ChainXavientois-8/+29
2021-01-31Use fully qualified syntax to avoid dynXavientois-2/+22
2021-01-31Remove unnecessary default keywordXavientois-4/+6
2021-01-31Remove stable annotationXavientois-3/+0
2021-01-31Fix formattingXavientois-10/+2
2021-01-31Add dyn for SizeHint castXavientois-1/+1
2021-01-31Remove exposing private traitXavientois-2/+2
2021-01-31Fix semicolonXavientois-1/+1
2021-01-31Add back lower_bound as memeberXavientois-0/+2
2021-01-31Add default keyword for specializationXavientois-5/+5
2021-01-31Fix incorrect tokenXavientois-1/+1
2021-01-31Move default to trait definitionXavientois-6/+4
2021-01-31Add missing genericXavientois-1/+1
2021-01-31Use helper trait to follow min_specialization rulesXavientois-4/+24
2021-01-31Fix implementation to specializeXavientois-1/+1
2021-01-31Implement size_hint for BufReaderXavientois-2/+21
2021-01-31Rollup merge of #78044 - oberien:empty-seek, r=m-ou-seJonas Schievink-2/+37
Implement io::Seek for io::Empty Fix #78029
2021-01-30impl Seek for Emptyoberien-2/+37
Fix #78029
2021-01-24Stabilize `Seek::stream_position` & change feature of `Seek::stream_len`Lukas Kalbertodt-5/+3
2021-01-21Rollup merge of #80172 - camelid:prelude-docs-consistent-punct, r=steveklabnikYuki Okushi-1/+1
Use consistent punctuation for 'Prelude contents' docs
2021-01-19Auto merge of #79705 - ijackson:bufwriter-disassemble, r=m-ou-sebors-0/+99
BufWriter: Provide into_raw_parts If something goes wrong, one might want to unpeel the layers of nested Writers to perform recovery actions on the underlying writer, or reuse its resources. `into_inner` can be used for this when the inner writer is still working. But when the inner writer is broken, and returning errors, `into_inner` simply gives you the error from flush, and the same `Bufwriter` back again. Here I provide the necessary function, which I have chosen to call `into_raw_parts`. I had to do something with `panicked`. Returning it to the caller as a boolean seemed rather bare. Throwing the buffered data away in this situation also seems unfriendly: maybe the programmer knows something about the underlying writer and can recover somehow. So I went for a custom Error. This may be overkill, but it does have the nice property that a caller who actually wants to look at the buffered data, rather than simply extracting the inner writer, will be told by the type system if they forget to handle the panicked case. If a caller doesn't need the buffer, it can just be discarded. That WriterPanicked is a newtype around Vec<u8> means that hopefully the layouts of the Ok and Err variants can be very similar, with just a boolean discriminant. So this custom error type should compile down to nearly no code. *If this general idea is felt appropriate, I will open a tracking issue, etc.*