Commit Graph

1426 Commits

Author SHA1 Message Date
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
Lzu Tao dd8f072233 Use drop instead of the toilet closure |_| () 2020-01-02 08:56:12 +00:00
David Tolnay 4646a88b7a Deprecate Error::description for real
`description` has been documented as soft-deprecated since 1.27.0 (17
months ago). There is no longer any reason to call it or implement it.

This commit:

- adds #[rustc_deprecated(since = "1.41.0")] to Error::description;

- moves description (and cause, which is also deprecated) below the
  source and backtrace methods in the Error trait;

- reduces documentation of description and cause to take up much less
  vertical real estate in rustdocs, while preserving the example that
  shows how to render errors without needing to call description;

- removes the description function of all *currently unstable* Error
  impls in the standard library;

- marks #[allow(deprecated)] the description function of all *stable*
  Error impls in the standard library;

- replaces miscellaneous uses of description in example code and the
  compiler.
2019-12-24 22:39:49 -08:00
Mazdak Farrokhzad 75b27ef59c Rollup merge of #67561 - euclio:remove-description, r=jonas-schievink
remove `description` from `Error` impls in docs

Since `description` is soft-deprecated, there's no need to show it implemented in these examples.
2019-12-24 04:40:00 +01:00
Andy Russell 24f3dcfdc7 remove description from Error impls in docs 2019-12-23 09:47:28 -06:00
Mazdak Farrokhzad 260514da94 Rollup merge of #67233 - Luro02:cursor_traits, r=sfackler
Add PartialEq and Eq to Cursor

closes #67226
2019-12-23 15:16:21 +01:00
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Luro02 89986a39a8 add partialeq and eq to cursor 2019-12-22 10:39:58 +01:00
Ross MacArthur f7256d28d1 Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
Alex Crichton 2fee28e713 std: Implement LineWriter::write_vectored
This commit implements the `write_vectored` method of the `LineWriter`
type. First discovered in bytecodealliance/wasmtime#629 the
`write_vectored` method of `Stdout` bottoms out here but only ends up
writing the first buffer due to the default implementation of
`write_vectored`.

Like `BufWriter`, however, `LineWriter` can have a non-default
implementation of `write_vectored` which tries to preserve the
vectored-ness as much as possible. Namely we can have a vectored write
for everything before the newline and everything after the newline if
all the stars align well.

Also like `BufWriter`, though, special care is taken to ensure that
whenever bytes are written we're sure to signal success since that
represents a "commit" of writing bytes.
2019-12-12 16:51:25 -08: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
Bryan Burgers 413ab57c02 docs: Fix link to BufWriter::flush
One of the links in the docs was being rendered as a literal
open-bracket followed by a single quote, instead of being transformed
into a link. Fix it to match the link earlier in the same paragraph.
2019-11-08 10:18:58 -06:00
Marco Conte 5b5196ad65 rephrase sentence regarding data loss when using BufReader::into_inner 2019-10-31 10:48:33 +00:00
Marco Conte 900c13e7f4 enhance the documentation of std::io::BufReader regarding potential data loss 2019-10-31 10:48:33 +00:00
Adrian Heine né Lang e697ffbbcb Fix parameter name in documentation 2019-10-20 23:13:41 +02:00
Ivan Tham 62e86b42b5 Fix inconsistent link formatting 2019-09-16 20:02:36 +08:00
Tomasz Różański a8c5f90b06 Fix inconsistent link formatting. 2019-09-11 14:03:40 +02: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
John Erickson 1b946106b7 clarify that not all errors are observed 2019-08-31 07:38:13 -07:00
John Erickson cccce09dda Add in generic type to description of BufReader and BufWriter 2019-08-31 07:38:13 -07:00
John Erickson c8e474871a Update BufWriter example to include call to flush() 2019-08-31 07:38:02 -07: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
Mazdak Farrokhzad b94e59cc41 Rollup merge of #62845 - RalfJung:read, r=rkruppe
read: fix doc comment

No idea how that happened...
2019-07-22 15:32:23 +02:00
Ralf Jung 8dc5635e13 read: fix doc comment 2019-07-21 12:47:34 +02:00
Ralf Jung 7c1e405478 ONCE_INIT is deprecated-in-future only for bootstrap 2019-07-19 09:48:06 +02:00
Ralf Jung 13ed0cf9e8 do not use mem::uninitialized in std::io 2019-07-19 09:45:38 +02:00
Mateusz Mikuła 124f6ef7cd Fix clippy::len_zero warnings 2019-07-18 15:14:56 +02:00
nathanwhit 04f0d309dc Remove last use of mem::uninitialized from std::io::util 2019-07-16 22:41:38 -04: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
Mazdak Farrokhzad c5d18600ef Rollup merge of #62381 - pawroman:fix_typo_in_write_vectored, r=Centril
Fix a typo in Write::write_vectored docs

Fixed what seems like a typo. "Copy to from" is extremely confusing.
2019-07-05 20:27:02 +02:00
Mark Rousskov 007d87f171 Permit use of mem::uninitialized via allow(deprecated) 2019-07-04 21:01:35 -04: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
Mazdak Farrokhzad 405edc71fd Rollup merge of #61235 - lzutao:stabilize-bufreader_buffer, r=Centril
Stabilize bufreader_buffer feature

FCP done in https://github.com/rust-lang/rust/issues/45323#issuecomment-495937047

Closes #45323

r? @SimonSapin
2019-05-29 08:15:58 +02:00
Lzu Tao 06eb412741 Stabilize bufreader_buffer feature 2019-05-27 13:42:21 +00:00
Chris Gregory b1ae49cae0 Annotate test with #[test] 2019-05-25 16:37:38 -05:00
Chris Gregory f27ec0f05f Add test that impl Seek for BufReader correctly invalidates buffer between seeks 2019-05-25 15:02:35 -05:00
Mazdak Farrokhzad a34dae3587 Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPC
Fix intra-doc link resolution failure on re-exporting libstd

Currently, re-exporting libstd items as below will [occur a lot of failures](https://gist.github.com/taiki-e/e33e0e8631ef47f65a74a3b69f456366).
```rust
pub use std::*;
```

Until the underlying issue (#56922) fixed, we can fix that so they don't propagate to downstream crates.

Related: https://github.com/rust-lang/rust/pull/56941 (That PR fixed failures that occur when re-exporting from libcore to libstd.)

r? @QuietMisdreavus
2019-05-20 23:02:59 +02:00
Brent Kerby 01cf36ebde Simplify BufRead doc example using NLL 2019-05-18 13:30:44 -06:00
Mazdak Farrokhzad bd17b5c9a2 Rollup merge of #60234 - tesaguri:cursor-default, r=Amanieu
std: Derive `Default` for `io::Cursor`

I think this change is quite obvious, so made it insta-stable, but I won't insist on that.
2019-05-09 23:56:11 +02:00
Peter Todd b9c430129d Inline some Cursor calls for slices
(Partially) brings back https://github.com/rust-lang/rust/pull/33921
2019-05-08 22:39:41 -04:00
Taiki Endo ccb9dac5ed Fix intra-doc link resolution failure on re-exporting libstd 2019-05-04 23:48:57 +09:00
Mazdak Farrokhzad ead8d81301 Rollup merge of #60334 - sfackler:stable-iovec, r=alexcrichton
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

r? @alexcrichton
2019-04-29 22:22:40 +02:00
Steven Fackler 89ff7cde5a tidy 2019-04-27 09:19:34 -07:00