rust/library/std/src/io
Matthias Krüger 1a9f91a43e
Rollup merge of #109174 - soerenmeier:cursor_fns, r=dtolnay
Replace `io::Cursor::{remaining_slice, is_empty}`

This is a late follow up to the concerns raised in https://github.com/rust-lang/rust/issues/86369.

https://github.com/rust-lang/rust/issues/86369#issuecomment-953096691
> This API seems focussed on the `Read` side of things. When `Seek`ing around and `Write`ing data, `is_empty` becomes confusing and `remaining_slice` is not very useful. When writing, the part of the slice before the cursor is much more interesting. Maybe we should have functions for both? Or a single function that returns both slices? (If we also have a `mut` version, a single function would be useful to allow mutable access to both sides at once.)

New feature name: `cursor_remaining` > `cursor_split`.
Added functions:
```rust
fn split(&self) -> (&[u8], &[u8]);
// fn before(&self) -> &[u8];
// fn after(&self) -> &[u8];
fn split_mut(&mut self) -> (&mut [u8], &mut [u8]);
// fn before_mut(&mut self) -> &mut [u8];
// fn after_mut(&mut self) -> &mut [u8];
```

A question was raised in https://github.com/rust-lang/rust/issues/86369#issuecomment-927124211 about whether to return a lifetime that would reflect the lifetime of the underlying bytes (`impl Cursor<&'a [u8]> { fn after(&self) -> &'a [u8] }`). The downside of doing this would be that it would not be possible to implement these functions generically over `T: AsRef<[u8]>`.

## Update
Based on the review, before* and after* methods where removed.
2024-07-29 07:11:13 +02:00
..
buffered Reformat use declarations. 2024-07-29 08:26:52 +10:00
copy Reformat use declarations. 2024-07-29 08:26:52 +10:00
cursor attempt to optimise vectored write 2022-06-26 17:15:31 +01:00
error Reformat use declarations. 2024-07-29 08:26:52 +10:00
impls std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
stdio Make default stdio lock() return 'static handles 2022-02-13 10:23:16 -05:00
util Reformat use declarations. 2024-07-29 08:26:52 +10:00
copy.rs unify read_to_end and io::copy impls for reading into a Vec 2023-11-26 18:13:36 +01:00
cursor.rs Rollup merge of #109174 - soerenmeier:cursor_fns, r=dtolnay 2024-07-29 07:11:13 +02:00
error.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
impls.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
mod.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
prelude.rs Use heading for std::prelude and not io::prelude 2021-01-05 17:52:24 -08:00
stdio.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
tests.rs Rollup merge of #109174 - soerenmeier:cursor_fns, r=dtolnay 2024-07-29 07:11:13 +02:00
util.rs Replace version placeholders for 1.79 2024-05-01 21:01:51 -04:00