1
Fork 0
Commit graph

576 commits

Author SHA1 Message Date
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
Guillaume Gomez
8835289434 Fix some rustdoc warnings 2017-12-20 17:50:02 +01:00
Matt Brubeck
3024c1434a Use Try syntax for Option in place of macros or match 2017-12-09 14:18:33 -08:00
kennytm
4c8cddb11b Rollup merge of #46224 - GuillaumeGomez:io-missing-link, r=QuietMisdreavus
Remove invalid doc link

r? @rust-lang/docs
2017-11-26 15:01:35 +08:00
Guillaume Gomez
377aaeae20 Remove invalid doc link 2017-11-23 21:48:22 +01:00
kennytm
9b090a0261 Rollup merge of #46050 - sunfishcode:read_to_end, r=sfackler
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.
2017-11-22 01:12:58 +08:00