rust/library/std/src/io
Yuki Okushi 4463b08652
Rollup merge of #86037 - soerenmeier:cursor_remaining, r=yaahc
Add `io::Cursor::{remaining, remaining_slice, is_empty}`

Tracking issue: #86369

I came across an inconvenience when answering the following [Stack Overflow](https://stackoverflow.com/questions/67831170) question.
To get the remaining slice you have to call `buff.fill_buf().unwrap()`. Which in my opinion doesn't really tell you what is returned (in the context of Cursor). To improve readability and convenience when using Cursor i propose adding the method `remaining`.

The next thing i found inconvenient (unnecessary long) was detecting if the cursor reached the end. There are a few ways this can be achieved right now:
- `buff.fill_buf().unwrap().is_empty()`
- `buff.position() >= buff.get_ref().len()`
- `buff.bytes().next().is_none()`

Which all seem a bit unintuitive, hidden in trait documentations or just a bit long for such a simple task.
Therefor i propose another method called `is_empty`, maybe with another name, since this one may leave room for interpretation on what really is empty (the underlying slice, the remaining slice or maybe the position).

Since it seemed easier to create this PR instead of an RFC i did that, if an RFC is wanted, i can close this PR and write an RFC first.
2021-06-22 07:37:46 +09:00
..
buffered Specialize io::Bytes::size_hint for more types 2021-06-10 19:16:55 +02:00
cursor Make some std::io functions const 2020-11-06 17:48:26 +01:00
error Add test for io::Error::new_const. 2021-03-21 20:22:26 +01:00
impls std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
stdio std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
util specialize io::copy to use the memory of the writer if it is a BufWriter 2021-01-31 14:58:03 +01:00
copy.rs library: Normalize safety-for-unsafe-block comments 2021-02-24 06:13:42 +01:00
cursor.rs rename remaining to remaining_slice and add a new remaining 2021-06-17 02:14:53 +02:00
error.rs Correct stability of ErrorKind::OutOfMemory 2021-05-03 10:28:19 +01:00
impls.rs Forwarding implementation for Seek trait's stream_position method 2021-06-07 19:21:22 -04:00
mod.rs Auto merge of #85815 - YuhanLiin:buf-read-data-left, r=m-ou-se 2021-06-18 20:11:51 +00:00
prelude.rs Use heading for std::prelude and not io::prelude 2021-01-05 17:52:24 -08:00
stdio.rs Rework at_exit to cleanup 2021-04-22 10:34:48 +02:00
tests.rs Auto merge of #85815 - YuhanLiin:buf-read-data-left, r=m-ou-se 2021-06-18 20:11:51 +00:00
util.rs Specialize io::Bytes::size_hint for more types 2021-06-10 19:16:55 +02:00