1
Fork 0
Commit graph

531 commits

Author SHA1 Message Date
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
Mazdak Farrokhzad
379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Matt Brubeck
b6fb3e3411 In doc examples, don't ignore read/write results
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-29 11:50:41 -07:00
Matt Brubeck
8dbae794b0 Use write_all instead of write in example code 2019-03-28 11:28:50 -07:00
Lukas Kalbertodt
c97d3d4dd1
Add tracking issue number for seek_convenience 2019-03-22 11:25:44 +01:00
bors
89573b3c8b Auto merge of #58422 - LukasKalbertodt:seek-convenience, r=alexcrichton
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-21 14:28:18 +00:00
Tobias Bucher
f95219fa58
Apply suggestions from code review
Fix typos in the documentation

Co-Authored-By: LukasKalbertodt <lukas.kalbertodt@gmail.com>
2019-03-17 09:39:47 +01:00
Lukas Kalbertodt
ea40aa46e7
Change "undefined" to "unspecified" in Seek::stream_len docs 2019-03-14 17:51:11 +01:00
Lukas Kalbertodt
598a1b4dd1
Avoid third seek operation in Seek::stream_len when possible 2019-03-14 13:43:17 +01:00
Lukas Kalbertodt
e8ee00a649
Add provided methods Seek::{stream_len, stream_position}
These two methods are defined in terms of `Seek::seek` and are
added for convenience. Tests are included.
2019-03-10 18:06:49 +01:00
Steven Fackler
ab8e1d264e Always call read/write from default vectored io methods 2019-03-07 19:31:58 -08:00
Taiki Endo
93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
Mazdak Farrokhzad
115c8a1f09
Rollup merge of #58703 - shepmaster:read_line_return, r=centril
Fix copy-pasted typo for read_string return value
2019-02-27 13:32:24 +01:00
bors
fb162e6944 Auto merge of #58357 - sfackler:vectored-io, r=alexcrichton
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-26 02:48:13 +00:00
Jake Goulding
f1b88abffb Fix copy-pasted typo for read_string return value 2019-02-25 12:14:02 -05:00
kennytm
e3a8f7db47
Rollup merge of #58553 - scottmcm:more-ihle, r=Centril
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-20 11:59:10 +08:00
Scott McMurray
3bea2ca49d Use more impl header lifetime elision
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-17 19:42:36 -08:00
Steven Fackler
5ca3b00ce0 Add a tracking issue 2019-02-13 20:26:57 -08:00
Steven Fackler
596f18201c impl Deref/DerefMut for IoVec types
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-13 19:40:17 -08:00
Steven Fackler
31bcec648a 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.
2019-02-13 19:40:17 -08:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad
ebbecac538
Rollup merge of #57296 - 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-12 10:54:58 +01:00
king6cong
d60fa1d3c2 Doc rewording, use the same name writer 2019-01-04 11:23:24 +08:00
Joseph Lyons
40658fdade Fixed the link to the ? operator 2019-01-03 00:20:31 -05:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Pietro Albini
cf9fd6074d
Rollup merge of #56363 - Lucretiel:patch-3, r=shepmaster
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-19 11:47:04 +01:00
Nathan West
a1790e8c20
Reordered match arms 2018-12-17 17:43:52 -08:00
Corey Farwell
c025d61409 Replace usages of ..i + 1 ranges with ..=i. 2018-12-04 12:05:19 -08:00
Nathan West
7c05ef5db0
Typo 2018-11-29 20:53:37 -05:00
Nathan West
697b83b307
Removed unnecessary buf subscript 2018-11-29 20:53:13 -05:00
Nathan West
f59d645a9b
Defactored Bytes::read
Removed unneeded refactoring of read_one_byte, which removed the unneeded dynamic dispatch (`dyn Read`) used by that function.
2018-11-29 20:36:32 -05:00
antoine-de
1ed91951c3 fix small doc mistake
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-11-21 11:17:48 +01:00
Marcus Griep
5285d35b49
Improve docs for std::io::Seek
Fixes #54562
2018-09-28 08:01:56 -04:00
Alva Snædís
aa4f73c845 Update documentation for fill_buf in std::io::BufRead
Brings the documentation in line with the BufReader implementation.

Fixes #48022.
2018-09-07 23:16:55 +00:00
ljedrz
b5ed39ff10 Implement custom read_to_end for io::Take 2018-08-01 13:26:45 +02:00
Simon Sapin
4ca77f702f Remove unstable and deprecated APIs 2018-07-30 18:18:23 +02:00
ljedrz
560d8079ec Deny bare trait objects in src/libstd. 2018-07-10 20:35:36 +02:00
Sgeo
0b9c686b47
Remove erroneous example of main as a non-Result function. 2018-06-19 18:32:44 -04:00
Simon Sapin
7cbeddb7b7 Deprecate Read::chars and char::decode_utf8
Per FCP:

* https://github.com/rust-lang/rust/issues/27802#issuecomment-377537778
* https://github.com/rust-lang/rust/issues/33906#issuecomment-377534308
2018-04-15 08:18:00 +02:00
Thayne McCombs
210a2a2b9e Stabilize take_set_limit
Fixes #42781
2018-04-05 00:30:49 -06:00
Matt Brubeck
1ce98f34d3 Cross-reference fs::read functions from io::Read docs 2018-04-03 15:25:55 -07:00
Corey Farwell
e9dcec070d Remove hidden foo functions from doc examples; use Termination trait.
Fixes https://github.com/rust-lang/rust/issues/49233.
2018-03-28 13:15:05 +02:00
Andreas Streichardt
f0a968eada Add missing link 2018-02-19 17:19:30 +01:00
Ross Light
e1e79d3a10 Remove "empty buffer" doc in read_until
This appears copied from fill_buf, but the above paragraph already indicates that a lack of delimiter at the end is EOF.
2018-02-15 07:32:42 -08:00
Guillaume Gomez
93969734f6 Add missing links 2018-01-08 14:16:16 +01:00
Sergio Benitez
d301da55f8 Clarify appending behavior of 'io::Read::read_to_string()'. 2018-01-05 04:24:12 -08:00