about summary refs log tree commit diff
path: root/src/libstd/io/mod.rs
AgeCommit message (Collapse)AuthorLines
2020-04-07Put reference to write_vectored in quotes in docThomas de Zeeuw-1/+1
2020-04-06Improve io::Write::write_all_vectored docsThomas de Zeeuw-11/+17
Also adds some more tests with different length IoSlices.
2020-04-01Fix link to write_vectoredThomas de Zeeuw-1/+1
2020-04-01Use unspecified over undefined in io::Write::write_all_vectored docsThomas de Zeeuw-7/+9
2020-03-31Add io::Write::write_all_vectoredThomas de Zeeuw-1/+161
Similar to io::Write::write_all but uses io::Write::write_vectored instead.
2020-03-24spaces between braces really ruin readabilityWithout Boats-4/+4
2020-03-24correct rustc versionWithout Boats-2/+2
2020-03-24IoSlice/IoSliceMut should be Send and SyncWithout Boats-0/+12
2020-03-21Tweak wording for std::io::Read::read functionadrian5-1/+1
2020-03-14Rollup merge of #69403 - LeSeulArtichaut:copy-ioslice, r=sfacklerYuki Okushi-0/+1
Implement `Copy` for `IoSlice` Resolves #69395 r? @sfackler
2020-03-10Rollup merge of #69514 - GuillaumeGomez:remove-spotlight, r=kinnisonMazdak Farrokhzad-2/+0
Remove spotlight I had a few comments saying that this feature was at best misunderstood or not even used so I decided to organize a poll about on [twitter](https://twitter.com/imperioworld_/status/1232769353503956994). After 87 votes, the result is very clear: it's not useful. Considering the amount of code we have just to run it, I think it's definitely worth it to remove it. r? @kinnison cc @ollie27
2020-03-06Don't redundantly repeat field names (clippy::redundant_field_names)Matthias Krüger-2/+2
2020-02-27use char instead of &str for single char patternsMatthias Krüger-2/+2
2020-02-27Remove spotlight usageGuillaume Gomez-2/+0
2020-02-23Implement `Copy` for `IoSlice`LeSeulArtichaut-0/+1
2020-01-28Document that write_all will not call write if given an empty bufferJosh Triplett-0/+2
Some types of Write instances have a semantic meaning associated with writing an empty buffer, such as sending an empty packet. This works when calling `write` directly, and supplying an empty buffer. However, calling `write_all` on an empty buffer will simply never call `write`, because `write_all` assumes it has no work to do. Document this behavior, to help prospective users of datagram-packet-style Write instances.
2019-12-22Format the worldMark Rousskov-2/+1
2019-12-21Require issue = "none" over issue = "0" in unstable attributesRoss MacArthur-1/+1
2019-12-05Simplify {IoSlice, IoSliceMut}::advance examples and testsTomasz Miąsko-29/+26
Remove unnecessary calls to `std::mem::replace` and make variables immutable.
2019-11-29Format libstd with rustfmtDavid Tolnay-79/+89
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libstd. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-09-16Fix inconsistent link formattingIvan Tham-6/+6
2019-09-03Changed comment to better reflect std's exceptional situationDaniel Henry-Mantilla-4/+4
2019-09-03Added warning around code with reference to uninit bytesDaniel Henry-Mantilla-0/+8
2019-08-06avoid unnecessary reservations in std::io::Take::read_to_endJack O'Connor-8/+58
Prevously the `read_to_end` implementation for `std::io::Take` used its own `limit` as a cap on the `reservation_size`. However, that could still result in an over-allocation like this: 1. Call `reader.take(5).read_to_end(&mut vec)`. 2. `read_to_end_with_reservation` reserves 5 bytes and calls `read`. 3. `read` writes 5 bytes. 4. `read_to_end_with_reservation` reserves 5 bytes and calls `read`. 5. `read` writes 0 bytes. 6. The read loop ends with `vec` having length 5 and capacity 10. The reservation of 5 bytes was correct for the read at step 2 but unnecessary for the read at step 4. By that second read, `Take::limit` is 0, but the `read_to_end_with_reservation` loop is still using the same `reservation_size` it started with. Solve this by having `read_to_end_with_reservation` take a closure, which lets it get a fresh `reservation_size` for each read. This is an implementation detail which doesn't affect any public API.
2019-08-03Add {IoSlice, IoSliceMut}::advanceThomas de Zeeuw-1/+199
2019-08-01Rollup merge of #62644 - arnottcr:std_io-doc, r=steveklabnikPietro Albini-1/+1
simplify std::io::Write::write rustdoc The std::io::Write::write method currensly suggests consumers guaranteed that `0 <= n <= buf.len()`, for `Ok(n)`, however `n` is of type `usize` causing the compiler to emit a warning: ``` warning: comparison is useless due to type limits --> lib.rs:6:18 | 6 | Ok(n) => 0 <= n && n <= output.len(), | ^^^^^^ | = note: #[warn(unused_comparisons)] on by default ``` This PR removes the suggestion to check `0 <= n` since it is moot. r? @steveklabnik
2019-07-28Rollup merge of #62806 - mati865:clippy, r=TimNNMazdak Farrokhzad-2/+2
Fix few Clippy warnings
2019-07-21read: fix doc commentRalf Jung-2/+2
2019-07-18Fix clippy::len_zero warningsMateusz Mikuła-2/+2
2019-07-13simplify std::io::Write::write rustdocColin Arnott-1/+1
The std::io::Write::write method currensly suggests consumers guaranteed that `0 <= n <= buf.len()`, for `Ok(n)`, however `n` is of type `usize` causing the compiler to emit a warning: ``` warning: comparison is useless due to type limits --> lib.rs:6:18 | 6 | Ok(n) => 0 <= n && n <= output.len(), | ^^^^^^ | = note: #[warn(unused_comparisons)] on by default ``` This PR removes the suggestion to check `0 <= n` since it is moot. r? @steveklabnik
2019-07-04Fix a typo in Write::write_vectored docsPaweł Romanowski-1/+1
2019-06-25tweak wordingRalf Jung-3/+3
2019-06-24call out explicitly that general read needs to be called with an initialized ↵Ralf Jung-1/+10
buffer
2019-05-18Simplify BufRead doc example using NLLBrent Kerby-9/+4
2019-04-27Stabilized vectored IOSteven Fackler-31/+31
This renames `std::io::IoVec` to `std::io::IoSlice` and `std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes `std::io::IoSlice`, `std::io::IoSliceMut`, `std::io::Read::read_vectored`, and `std::io::Write::write_vectored`. Closes #58452
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