1
Fork 0
Commit graph

576 commits

Author SHA1 Message Date
mark
2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00
Tomasz Miąsko
7a5d3abfb1 Avoid writes without any data in Write::write_all_vectored
Previously, when non-empty sequence of empty IoSlices have been provided
to `Write::write_all_vectored`, the buffers would be written as is with
`Write::write_vectored` and subsequently the return value `Ok(0)` would
be misinterpreted as an error.

Avoid writes without any data by advancing the buffers first. This
matches the documented behaviour of `Write::write_all_vectored`
and is analogous to what happens in `Write::write_all`.
2020-07-26 12:25:02 +02:00
Alexis Bourget
471dd52d77 Fix merge conflict with recent PR 2020-07-19 22:15:44 +02:00
Alexis Bourget
e88220f867 Fix small nit in the link to read 2020-07-19 15:30:32 +02:00
Manish Goregaokar
8d470b5796
Update src/libstd/io/mod.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-07-18 22:31:35 -07:00
Manish Goregaokar
26ba0e12e8 Use intra-doc links in std::io 2020-07-18 16:13:04 -07:00
Alexis Bourget
d88cce2423 Add a link to read in the read_exact doc about the guarantees 2020-07-18 23:20:58 +02:00
Manish Goregaokar
3cecd6003b Revert "Remove spotlight usage"
This reverts commit 13c6d5819a.
2020-07-16 09:58:34 -07:00
Alexis Bourget
d8cc2c1e4f Add a warning about infinite reading in read_(until|line) 2020-06-01 16:19:10 +02:00
Elinvynia
05fc7faacb Better documentation for io::Read::read() return value 2020-05-09 01:17:20 +02:00
Dylan DPC
fb1aa5624d
Rollup merge of #71296 - ChiefMilesEdgeworth:fix_doc_wording, r=Dylan-DPC
Change wording on read_vectored docs

Closes #70154

I'm happy to work with others to make the wording on this more clear. I think what I have is an improvement but may not be the final wording.
2020-04-29 12:23:22 +02:00
Steven Fackler
5d8fe1c4e6 Suppress file length check temporarily
Will clean up in a separate PR
2020-04-26 04:48:51 -07:00
Steven Fackler
07443f17d4 Update name 2020-04-26 04:24:16 -07:00
Steven Fackler
15262ec6be Add Read/Write::can_read/write_vectored
When working with an arbitrary reader or writer, code that uses vectored
operations may end up being slower than code that copies into a single
buffer when the underlying reader or writer doesn't actually support
vectored operations. These new methods allow you to ask the reader or
witer up front if vectored operations are efficiently supported.

Currently, you have to use some heuristics to guess by e.g. checking if
the read or write only accessed the first buffer. Hyper is one concrete
example of a library that has to do this dynamically:
0eaf304644/src/proto/h1/io.rs (L582-L594)
2020-04-26 04:23:39 -07:00
Nathan Abel
3a40cbb665 Change wording on read_vectored docs 2020-04-18 14:30:16 -04:00
Thomas de Zeeuw
5d09f9f051 Put reference to write_vectored in quotes in doc 2020-04-07 00:00:07 +02:00
Thomas de Zeeuw
63118d1fd7 Improve io::Write::write_all_vectored docs
Also adds some more tests with different length IoSlices.
2020-04-06 11:21:15 +02:00
Thomas de Zeeuw
ba91e7e374 Fix link to write_vectored 2020-04-01 19:41:57 +02:00
Thomas de Zeeuw
9745b1fc52 Use unspecified over undefined in io::Write::write_all_vectored docs 2020-04-01 15:39:05 +02:00
Thomas de Zeeuw
33a49993b4 Add io::Write::write_all_vectored
Similar to io::Write::write_all but uses io::Write::write_vectored
instead.
2020-03-31 20:22:09 +02:00
Without Boats
03c64bf532 spaces between braces really ruin readability 2020-03-24 15:39:29 +01:00
Without Boats
3cc4ef9326 correct rustc version 2020-03-24 00:34:48 +01:00
Without Boats
4dda632faf IoSlice/IoSliceMut should be Send and Sync 2020-03-24 00:33:25 +01:00
adrian5
0b307f7a9f
Tweak wording for std::io::Read::read function 2020-03-21 17:06:10 +01:00
Yuki Okushi
5d90154886
Rollup merge of #69403 - LeSeulArtichaut:copy-ioslice, r=sfackler
Implement `Copy` for `IoSlice`

Resolves #69395

r? @sfackler
2020-03-14 04:03:20 +09:00
Mazdak Farrokhzad
61150353bf
Rollup merge of #69514 - GuillaumeGomez:remove-spotlight, r=kinnison
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-10 06:47:47 +01:00
Matthias Krüger
83980aca20 Don't redundantly repeat field names (clippy::redundant_field_names) 2020-03-06 19:42:18 +01:00
Matthias Krüger
7c84ba1124 use char instead of &str for single char patterns 2020-02-27 14:57:22 +01:00
Guillaume Gomez
13c6d5819a Remove spotlight usage 2020-02-27 14:51:22 +01:00
LeSeulArtichaut
79b8ad84c8 Implement Copy for IoSlice 2020-02-23 18:32:36 +01:00
Josh Triplett
9bb2a50e04 Document that write_all will not call write if given an empty buffer
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.
2020-01-28 17:22:38 -08:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Ross MacArthur
f7256d28d1
Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
Tomasz Miąsko
92bc35f7b6 Simplify {IoSlice, IoSliceMut}::advance examples and tests
Remove unnecessary calls to `std::mem::replace` and make variables immutable.
2019-12-05 00:00:00 +00:00
David Tolnay
4436c9d354
Format libstd with rustfmt
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-11-29 18:43:27 -08:00
Ivan Tham
62e86b42b5
Fix inconsistent link formatting 2019-09-16 20:02:36 +08:00
Daniel Henry-Mantilla
b03d3dc478 Changed comment to better reflect std's exceptional situation 2019-09-03 15:36:21 +02:00
Daniel Henry-Mantilla
23c76ff7b9 Added warning around code with reference to uninit bytes 2019-09-03 12:18:09 +02:00
Jack O'Connor
edb5214b29 avoid unnecessary reservations in std::io::Take::read_to_end
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-06 10:15:11 -04:00
Thomas de Zeeuw
dad56c3947 Add {IoSlice, IoSliceMut}::advance 2019-08-03 10:44:45 +02:00
Pietro Albini
9ff52752d8
Rollup merge of #62644 - arnottcr:std_io-doc, r=steveklabnik
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-08-01 16:00:22 +02:00
Mazdak Farrokhzad
b405aa2d03
Rollup merge of #62806 - mati865:clippy, r=TimNN
Fix few Clippy warnings
2019-07-28 11:11:08 +02:00
Ralf Jung
8dc5635e13 read: fix doc comment 2019-07-21 12:47:34 +02:00
Mateusz Mikuła
124f6ef7cd Fix clippy::len_zero warnings 2019-07-18 15:14:56 +02:00
Colin Arnott
e8e13f04b2
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-13 01:50:45 +00:00
Paweł Romanowski
7f035baaf7 Fix a typo in Write::write_vectored docs 2019-07-04 18:44:34 +02:00
Ralf Jung
390f717a0a tweak wording 2019-06-25 22:59:00 +02:00
Ralf Jung
1c12b1be33 call out explicitly that general read needs to be called with an initialized buffer 2019-06-24 22:58:53 +02:00
Brent Kerby
01cf36ebde Simplify BufRead doc example using NLL 2019-05-18 13:30:44 -06:00
Steven Fackler
bd177f3ea3 Stabilized vectored IO
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-04-27 08:34:08 -07:00