/// Advance the internal cursor of the slice.
///
+ /// Also see [`IoSliceMut::advance_slices`] to advance the cursors of
+ /// multiple buffers.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(io_slice_advance)]
+ ///
+ /// use std::io::IoSliceMut;
+ /// use std::ops::Deref;
+ ///
+ /// let mut data = [1; 8];
+ /// let mut buf = IoSliceMut::new(&mut data);
+ ///
+ /// // Mark 3 bytes as read.
+ /// buf.advance(3);
+ /// assert_eq!(buf.deref(), [1; 5].as_ref());
+ /// ```
+ #[unstable(feature = "io_slice_advance", issue = "62726")]
+ #[inline]
+ pub fn advance(&mut self, n: usize) {
+ self.0.advance(n)
+ }
+
+ /// Advance the internal cursor of the slices.
+ ///
/// # Notes
///
/// Elements in the slice may be modified if the cursor is not advanced to
/// ][..];
///
/// // 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.
*bufs = &mut replace(bufs, &mut [])[remove..];
if !bufs.is_empty() {
- bufs[0].0.advance(n - accumulated_len)
+ bufs[0].advance(n - accumulated_len)
}
}
}
/// Advance the internal cursor of the slice.
///
+ /// Also see [`IoSlice::advance_slices`] to advance the cursors of multiple
+ /// buffers.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(io_slice_advance)]
+ ///
+ /// use std::io::IoSlice;
+ /// use std::ops::Deref;
+ ///
+ /// let mut data = [1; 8];
+ /// let mut buf = IoSlice::new(&mut data);
+ ///
+ /// // Mark 3 bytes as read.
+ /// buf.advance(3);
+ /// assert_eq!(buf.deref(), [1; 5].as_ref());
+ /// ```
+ #[unstable(feature = "io_slice_advance", issue = "62726")]
+ #[inline]
+ pub fn advance(&mut self, n: usize) {
+ self.0.advance(n)
+ }
+
+ /// Advance the internal cursor of the slices.
+ ///
/// # Notes
///
/// Elements in the slice may be modified if the cursor is not advanced to
/// ][..];
///
/// // 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.
*bufs = &mut replace(bufs, &mut [])[remove..];
if !bufs.is_empty() {
- bufs[0].0.advance(n - accumulated_len)
+ bufs[0].advance(n - accumulated_len)
}
}
}
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) => {
&"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),
}