mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Rename IoSlice(Mut)::advance_slice to advance_slices
This commit is contained in:
parent
49e25b5ef2
commit
fd14c52075
@ -1045,7 +1045,7 @@ impl<'a> IoSliceMut<'a> {
|
||||
|
||||
/// Advance the internal cursor of the slice.
|
||||
///
|
||||
/// Also see [`IoSliceMut::advance_slice`] to advance the cursors of
|
||||
/// Also see [`IoSliceMut::advance_slices`] to advance the cursors of
|
||||
/// multiple buffers.
|
||||
///
|
||||
/// # Examples
|
||||
@ -1097,13 +1097,13 @@ impl<'a> IoSliceMut<'a> {
|
||||
/// ][..];
|
||||
///
|
||||
/// // Mark 10 bytes as read.
|
||||
/// IoSliceMut::advance_slice(&mut bufs, 10);
|
||||
/// IoSliceMut::advance_slices(&mut bufs, 10);
|
||||
/// assert_eq!(bufs[0].deref(), [2; 14].as_ref());
|
||||
/// assert_eq!(bufs[1].deref(), [3; 8].as_ref());
|
||||
/// ```
|
||||
#[unstable(feature = "io_slice_advance", issue = "62726")]
|
||||
#[inline]
|
||||
pub fn advance_slice(bufs: &mut &mut [IoSliceMut<'a>], n: usize) {
|
||||
pub fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize) {
|
||||
// Number of buffers to remove.
|
||||
let mut remove = 0;
|
||||
// Total length of all the to be removed buffers.
|
||||
@ -1179,7 +1179,7 @@ impl<'a> IoSlice<'a> {
|
||||
|
||||
/// Advance the internal cursor of the slice.
|
||||
///
|
||||
/// Also see [`IoSlice::advance_slice`] to advance the cursors of multiple
|
||||
/// Also see [`IoSlice::advance_slices`] to advance the cursors of multiple
|
||||
/// buffers.
|
||||
///
|
||||
/// # Examples
|
||||
@ -1231,12 +1231,12 @@ impl<'a> IoSlice<'a> {
|
||||
/// ][..];
|
||||
///
|
||||
/// // Mark 10 bytes as written.
|
||||
/// IoSlice::advance_slice(&mut bufs, 10);
|
||||
/// IoSlice::advance_slices(&mut bufs, 10);
|
||||
/// assert_eq!(bufs[0].deref(), [2; 14].as_ref());
|
||||
/// assert_eq!(bufs[1].deref(), [3; 8].as_ref());
|
||||
#[unstable(feature = "io_slice_advance", issue = "62726")]
|
||||
#[inline]
|
||||
pub fn advance_slice(bufs: &mut &mut [IoSlice<'a>], n: usize) {
|
||||
pub fn advance_slices(bufs: &mut &mut [IoSlice<'a>], n: usize) {
|
||||
// Number of buffers to remove.
|
||||
let mut remove = 0;
|
||||
// Total length of all the to be removed buffers.
|
||||
@ -1562,7 +1562,7 @@ pub trait Write {
|
||||
fn write_all_vectored(&mut self, mut bufs: &mut [IoSlice<'_>]) -> Result<()> {
|
||||
// Guarantee that bufs is empty if it contains no data,
|
||||
// to avoid calling write_vectored if there is no data to be written.
|
||||
IoSlice::advance_slice(&mut bufs, 0);
|
||||
IoSlice::advance_slices(&mut bufs, 0);
|
||||
while !bufs.is_empty() {
|
||||
match self.write_vectored(bufs) {
|
||||
Ok(0) => {
|
||||
@ -1571,7 +1571,7 @@ pub trait Write {
|
||||
&"failed to write whole buffer",
|
||||
));
|
||||
}
|
||||
Ok(n) => IoSlice::advance_slice(&mut bufs, n),
|
||||
Ok(n) => IoSlice::advance_slices(&mut bufs, n),
|
||||
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ fn test_read_to_end_capacity() -> io::Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn io_slice_mut_advance_slice() {
|
||||
fn io_slice_mut_advance_slices() {
|
||||
let mut buf1 = [1; 8];
|
||||
let mut buf2 = [2; 16];
|
||||
let mut buf3 = [3; 8];
|
||||
@ -364,75 +364,75 @@ fn io_slice_mut_advance_slice() {
|
||||
][..];
|
||||
|
||||
// Only in a single buffer..
|
||||
IoSliceMut::advance_slice(&mut bufs, 1);
|
||||
IoSliceMut::advance_slices(&mut bufs, 1);
|
||||
assert_eq!(bufs[0].deref(), [1; 7].as_ref());
|
||||
assert_eq!(bufs[1].deref(), [2; 16].as_ref());
|
||||
assert_eq!(bufs[2].deref(), [3; 8].as_ref());
|
||||
|
||||
// Removing a buffer, leaving others as is.
|
||||
IoSliceMut::advance_slice(&mut bufs, 7);
|
||||
IoSliceMut::advance_slices(&mut bufs, 7);
|
||||
assert_eq!(bufs[0].deref(), [2; 16].as_ref());
|
||||
assert_eq!(bufs[1].deref(), [3; 8].as_ref());
|
||||
|
||||
// Removing a buffer and removing from the next buffer.
|
||||
IoSliceMut::advance_slice(&mut bufs, 18);
|
||||
IoSliceMut::advance_slices(&mut bufs, 18);
|
||||
assert_eq!(bufs[0].deref(), [3; 6].as_ref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn io_slice_mut_advance_slice_empty_slice() {
|
||||
fn io_slice_mut_advance_slices_empty_slice() {
|
||||
let mut empty_bufs = &mut [][..];
|
||||
// Shouldn't panic.
|
||||
IoSliceMut::advance_slice(&mut empty_bufs, 1);
|
||||
IoSliceMut::advance_slices(&mut empty_bufs, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn io_slice_mut_advance_slice_beyond_total_length() {
|
||||
fn io_slice_mut_advance_slices_beyond_total_length() {
|
||||
let mut buf1 = [1; 8];
|
||||
let mut bufs = &mut [IoSliceMut::new(&mut buf1)][..];
|
||||
|
||||
// Going beyond the total length should be ok.
|
||||
IoSliceMut::advance_slice(&mut bufs, 9);
|
||||
IoSliceMut::advance_slices(&mut bufs, 9);
|
||||
assert!(bufs.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn io_slice_advance_slice() {
|
||||
fn io_slice_advance_slices() {
|
||||
let buf1 = [1; 8];
|
||||
let buf2 = [2; 16];
|
||||
let buf3 = [3; 8];
|
||||
let mut bufs = &mut [IoSlice::new(&buf1), IoSlice::new(&buf2), IoSlice::new(&buf3)][..];
|
||||
|
||||
// Only in a single buffer..
|
||||
IoSlice::advance_slice(&mut bufs, 1);
|
||||
IoSlice::advance_slices(&mut bufs, 1);
|
||||
assert_eq!(bufs[0].deref(), [1; 7].as_ref());
|
||||
assert_eq!(bufs[1].deref(), [2; 16].as_ref());
|
||||
assert_eq!(bufs[2].deref(), [3; 8].as_ref());
|
||||
|
||||
// Removing a buffer, leaving others as is.
|
||||
IoSlice::advance_slice(&mut bufs, 7);
|
||||
IoSlice::advance_slices(&mut bufs, 7);
|
||||
assert_eq!(bufs[0].deref(), [2; 16].as_ref());
|
||||
assert_eq!(bufs[1].deref(), [3; 8].as_ref());
|
||||
|
||||
// Removing a buffer and removing from the next buffer.
|
||||
IoSlice::advance_slice(&mut bufs, 18);
|
||||
IoSlice::advance_slices(&mut bufs, 18);
|
||||
assert_eq!(bufs[0].deref(), [3; 6].as_ref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn io_slice_advance_slice_empty_slice() {
|
||||
fn io_slice_advance_slices_empty_slice() {
|
||||
let mut empty_bufs = &mut [][..];
|
||||
// Shouldn't panic.
|
||||
IoSlice::advance_slice(&mut empty_bufs, 1);
|
||||
IoSlice::advance_slices(&mut empty_bufs, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn io_slice_advance_slice_beyond_total_length() {
|
||||
fn io_slice_advance_slices_beyond_total_length() {
|
||||
let buf1 = [1; 8];
|
||||
let mut bufs = &mut [IoSlice::new(&buf1)][..];
|
||||
|
||||
// Going beyond the total length should be ok.
|
||||
IoSlice::advance_slice(&mut bufs, 9);
|
||||
IoSlice::advance_slices(&mut bufs, 9);
|
||||
assert!(bufs.is_empty());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user