about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
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
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.*
2021-01-17Add benchmark and fast path for BufReader::read_exactBen Kimock-17/+47
2021-01-14Rollup merge of #80895 - sfackler:read-to-end-ub, r=m-ou-seMara Bos-12/+10
Fix handling of malicious Readers in read_to_end A malicious `Read` impl could return overly large values from `read`, which would result in the guard's drop impl setting the buffer's length to greater than its capacity! ~~To fix this, the drop impl now uses the safe `truncate` function instead of `set_len` which ensures that this will not happen. The result of calling the function will be nonsensical, but that's fine given the contract violation of the `Read` impl.~~ ~~The `Guard` type is also used by `append_to_string` which does not pass untrusted values into the length field, so I've copied the guard type into each function and only modified the one used by `read_to_end`. We could just keep a single one and modify it, but it seems a bit cleaner to keep the guard code close to the functions and related specifically to them.~~ To fix this, we now assert that the returned length is not larger than the buffer passed to the method. For reference, this bug has been present for ~2.5 years since 1.20: https://github.com/rust-lang/rust/commit/ecbb896b9eb2acadefde57be493e4298c1aa04a3. Closes #80894.
2021-01-14Rollup merge of #80217 - camelid:io-read_to_string, r=m-ou-seMara Bos-0/+48
Add a `std::io::read_to_string` function I recognize that you're usually supposed to open an issue first, but the implementation is very small so it's okay if this is closed and it was 'wasted work' :) ----- The equivalent of `std::fs::read_to_string`, but generalized to all `Read` impls. As the documentation on `std::io::read_to_string` says, the advantage of this function is that it means you don't have to create a variable first and it provides more type safety since you can only get the buffer out if there were no errors. If you use `Read::read_to_string`, you have to remember to check whether the read succeeded because otherwise your buffer will be empty. It's friendlier to newcomers and better in most cases to use an explicit return value instead of an out parameter.
2021-01-11Add docs on performanceCamelid-0/+13
2021-01-11clarify docs a bitSteven Fackler-4/+3
2021-01-11make check a bit more clearSteven Fackler-2/+3
2021-01-11clean up control flowSteven Fackler-11/+2
2021-01-11Fix handling of malicious Readers in read_to_endSteven Fackler-1/+8
2021-01-05Use heading for `std::prelude` and not `io::prelude`Camelid-1/+1
The heading style for `std::prelude` is to be consistent with the headings for `std` and `core`: `# The Rust Standard Library` and `# The Rust Core Library`, respectively.
2021-01-04BufWriter::into_raw_parts: Add tracking issue numberIan Jackson-6/+6
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>