Skip to content

Commit 49e25b5

Browse files
committed
Add IoSlice(Mut)::advance
Advance the internal cursor of a single slice.
1 parent 3803c09 commit 49e25b5

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

library/std/src/io/mod.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,32 @@ impl<'a> IoSliceMut<'a> {
10451045

10461046
/// Advance the internal cursor of the slice.
10471047
///
1048+
/// Also see [`IoSliceMut::advance_slice`] to advance the cursors of
1049+
/// multiple buffers.
1050+
///
1051+
/// # Examples
1052+
///
1053+
/// ```
1054+
/// #![feature(io_slice_advance)]
1055+
///
1056+
/// use std::io::IoSliceMut;
1057+
/// use std::ops::Deref;
1058+
///
1059+
/// let mut data = [1; 8];
1060+
/// let mut buf = IoSliceMut::new(&mut data);
1061+
///
1062+
/// // Mark 10 bytes as read.
1063+
/// buf.advance(3);
1064+
/// assert_eq!(buf.deref(), [1; 5].as_ref());
1065+
/// ```
1066+
#[unstable(feature = "io_slice_advance", issue = "62726")]
1067+
#[inline]
1068+
pub fn advance(&mut self, n: usize) {
1069+
self.0.advance(n)
1070+
}
1071+
1072+
/// Advance the internal cursor of the slices.
1073+
///
10481074
/// # Notes
10491075
///
10501076
/// Elements in the slice may be modified if the cursor is not advanced to
@@ -1093,7 +1119,7 @@ impl<'a> IoSliceMut<'a> {
10931119

10941120
*bufs = &mut replace(bufs, &mut [])[remove..];
10951121
if !bufs.is_empty() {
1096-
bufs[0].0.advance(n - accumulated_len)
1122+
bufs[0].advance(n - accumulated_len)
10971123
}
10981124
}
10991125
}
@@ -1153,6 +1179,32 @@ impl<'a> IoSlice<'a> {
11531179

11541180
/// Advance the internal cursor of the slice.
11551181
///
1182+
/// Also see [`IoSlice::advance_slice`] to advance the cursors of multiple
1183+
/// buffers.
1184+
///
1185+
/// # Examples
1186+
///
1187+
/// ```
1188+
/// #![feature(io_slice_advance)]
1189+
///
1190+
/// use std::io::IoSlice;
1191+
/// use std::ops::Deref;
1192+
///
1193+
/// let mut data = [1; 8];
1194+
/// let mut buf = IoSlice::new(&mut data);
1195+
///
1196+
/// // Mark 10 bytes as read.
1197+
/// buf.advance(3);
1198+
/// assert_eq!(buf.deref(), [1; 5].as_ref());
1199+
/// ```
1200+
#[unstable(feature = "io_slice_advance", issue = "62726")]
1201+
#[inline]
1202+
pub fn advance(&mut self, n: usize) {
1203+
self.0.advance(n)
1204+
}
1205+
1206+
/// Advance the internal cursor of the slices.
1207+
///
11561208
/// # Notes
11571209
///
11581210
/// Elements in the slice may be modified if the cursor is not advanced to
@@ -1200,7 +1252,7 @@ impl<'a> IoSlice<'a> {
12001252

12011253
*bufs = &mut replace(bufs, &mut [])[remove..];
12021254
if !bufs.is_empty() {
1203-
bufs[0].0.advance(n - accumulated_len)
1255+
bufs[0].advance(n - accumulated_len)
12041256
}
12051257
}
12061258
}

0 commit comments

Comments
 (0)