about summary refs log tree commit diff
path: root/src/libstd/io/mod.rs
AgeCommit message (Collapse)AuthorLines
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-4/+4
2019-03-29In doc examples, don't ignore read/write resultsMatt Brubeck-6/+19
Calling `Read::read` or `Write::write` without checking the returned `usize` value is almost always an error. Example code in the documentation should demonstrate how to use the return value correctly. Otherwise, people might copy the example code thinking that it is okay to "fire and forget" these methods.
2019-03-28Use write_all instead of write in example codeMatt Brubeck-1/+1
2019-03-22Add tracking issue number for `seek_convenience`Lukas Kalbertodt-2/+2
2019-03-21Auto merge of #58422 - LukasKalbertodt:seek-convenience, r=alexcrichtonbors-2/+126
Add provided methods `Seek::{stream_len, stream_position}` This adds two new, provided methods to the `io::Seek` trait: - `fn stream_len(&mut self) -> Result<u64>` - `fn stream_position(&mut self) -> Result<u64>` Both are added for convenience and to improve readability in user code. Reading `file.stream_len()` is much better than to manually seek two or three times. Similarly, `file.stream_position()` is much more clear than `file.seek(SeekFrom::Current(0))`. You can find prior discussions [in this internals thread](https://internals.rust-lang.org/t/pre-rfc-idea-extend-io-seek-with-convenience-methods-with-e-g-stream-len/9262). I think I addressed all concerns in that thread. I already wrote three RFCs to add a small new API to libstd but I noticed that many public changes to libstd happen without an RFC. So I figured I can try opening a PR directly without going through RFCs first. After all, we do have rfcbot here too. If you think this change is too big to merge without an RFC, I can still close this PR and write an RFC.
2019-03-17Apply suggestions from code review Tobias Bucher-2/+2
Fix typos in the documentation Co-Authored-By: LukasKalbertodt <lukas.kalbertodt@gmail.com>
2019-03-14Change "undefined" to "unspecified" in `Seek::stream_len` docsLukas Kalbertodt-1/+1
2019-03-14Avoid third seek operation in `Seek::stream_len` when possibleLukas Kalbertodt-5/+12
2019-03-10Add provided methods `Seek::{stream_len, stream_position}`Lukas Kalbertodt-2/+119
These two methods are defined in terms of `Seek::seek` and are added for convenience. Tests are included.
2019-03-07Always call read/write from default vectored io methodsSteven Fackler-12/+28
2019-02-28libstd => 2018Taiki Endo-12/+11
2019-02-27Rollup merge of #58703 - shepmaster:read_line_return, r=centrilMazdak Farrokhzad-1/+1
Fix copy-pasted typo for read_string return value
2019-02-26Auto merge of #58357 - sfackler:vectored-io, r=alexcrichtonbors-1/+131
Add vectored read and write support This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies. r? @alexcrichton
2019-02-25Fix copy-pasted typo for read_string return valueJake Goulding-1/+1
2019-02-20Rollup merge of #58553 - scottmcm:more-ihle, r=Centrilkennytm-2/+2
Use more impl header lifetime elision Inspired by seeing explicit lifetimes on these two: - https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator - https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore. Most of the changes in here fall into two big categories: - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm). I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-17Use more impl header lifetime elisionScott McMurray-2/+2
There are two big categories of changes in here - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-13Add a tracking issueSteven Fackler-11/+11
2019-02-13impl Deref/DerefMut for IoVec typesSteven Fackler-14/+22
Returning &'a mut [u8] was unsound, and we may as well just have them directly deref to their slices to make it easier to work with them.
2019-02-13Add vectored read and write supportSteven Fackler-1/+123
This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies.
2019-02-10libs: doc commentsAlexander Regueiro-3/+3
2019-01-12Rollup merge of #57296 - ↵Mazdak Farrokhzad-1/+1
JosephTLyons:Fix-question-mark-operator-in-stdio-document, r=wesleywiser Fixed the link to the ? operator I'm working on updating all broken links, but figured I'd break up the pull requests so they are easier to review, versus just one big pull request.
2019-01-04Doc rewording, use the same name `writer`king6cong-2/+2
2019-01-03Fixed the link to the ? operatorJoseph Lyons-1/+1
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-19Rollup merge of #56363 - Lucretiel:patch-3, r=shepmasterPietro Albini-13/+10
Defactored Bytes::read Removed unneeded refactoring of read_one_byte, which removed the unneeded dynamic dispatch (`dyn Read`) used by that function. This function is only used in one place in the entire Rust codebase; there doesn't seem to be a reason for it to exist (and there especially doesn't seem to be a reason for it to use dynamic dispatch)
2018-12-17Reordered match armsNathan West-1/+1
2018-12-04Replace usages of `..i + 1` ranges with `..=i`.Corey Farwell-1/+1
2018-11-29TypoNathan West-1/+1
2018-11-29Removed unnecessary buf subscriptNathan West-4/+5
2018-11-29Defactored Bytes::readNathan West-13/+9
Removed unneeded refactoring of read_one_byte, which removed the unneeded dynamic dispatch (`dyn Read`) used by that function.
2018-11-21fix small doc mistakeantoine-de-1/+1
The std::io::read main documentation can lead to error because the buffer is prefilled with 10 zeros that will pad the response. Using an empty vector is better. The `read_to_end` documentation is already correct though. This is my first rust PR, don't hesitate to tell me if I did something wrong.
2018-09-28Improve docs for std::io::SeekMarcus Griep-2/+2
Fixes #54562
2018-09-07Update documentation for fill_buf in std::io::BufReadAlva Snædís-1/+2
Brings the documentation in line with the BufReader implementation. Fixes #48022.
2018-08-01Implement custom read_to_end for io::Takeljedrz-3/+16
2018-07-30Remove unstable and deprecated APIsSimon Sapin-148/+0
2018-07-10Deny bare trait objects in `src/libstd`.ljedrz-2/+2
2018-06-19Remove erroneous example of main as a non-Result function.Sgeo-1/+1
2018-04-15Deprecate Read::chars and char::decode_utf8Simon Sapin-1/+13
Per FCP: * https://github.com/rust-lang/rust/issues/27802#issuecomment-377537778 * https://github.com/rust-lang/rust/issues/33906#issuecomment-377534308
2018-04-05Stabilize take_set_limitThayne McCombs-2/+1
Fixes #42781
2018-04-03Cross-reference fs::read functions from io::Read docsMatt Brubeck-0/+10
2018-03-28Remove hidden `foo` functions from doc examples; use `Termination` trait.Corey Farwell-303/+302
Fixes https://github.com/rust-lang/rust/issues/49233.
2018-02-19Add missing linkAndreas Streichardt-0/+2
2018-02-15Remove "empty buffer" doc in read_untilRoss Light-2/+0
This appears copied from fill_buf, but the above paragraph already indicates that a lack of delimiter at the end is EOF.
2018-01-08Add missing linksGuillaume Gomez-7/+14
2018-01-05Clarify appending behavior of 'io::Read::read_to_string()'.Sergio Benitez-1/+1
2017-12-20Fix some rustdoc warningsGuillaume Gomez-2/+3
2017-12-09Use Try syntax for Option in place of macros or matchMatt Brubeck-4/+3
2017-11-26Rollup merge of #46224 - GuillaumeGomez:io-missing-link, r=QuietMisdreavuskennytm-2/+1
Remove invalid doc link r? @rust-lang/docs
2017-11-23Remove invalid doc linkGuillaume Gomez-2/+1
2017-11-22Rollup merge of #46050 - sunfishcode:read_to_end, r=sfacklerkennytm-6/+3
Optimize `read_to_end`. This patch makes `read_to_end` use Vec's memory-growth pattern rather than using a custom pattern. This has some interesting effects: - If memory is reserved up front, `read_to_end` can be faster, as it starts reading at the buffer size, rather than always starting at 32 bytes. This speeds up file reading by 2x in one of my use cases. - It can reduce the number of syscalls when reading large files. Previously, `read_to_end` would settle into a sequence of 8192-byte reads. With this patch, the read size follows Vec's allocation pattern. For example, on a 16MiB file, it can do 21 read syscalls instead of 2057. In simple benchmarks of large files though, overall speed is still dominated by the actual I/O. - A downside is that Read implementations that don't implement `initializer()` may see increased memory zeroing overhead. I benchmarked this on a variety of data sizes, with and without preallocated buffers. Most benchmarks see no difference, but reading a small/medium file with a pre-allocated buffer is faster.