@@ -1084,6 +1084,10 @@ impl<'a> IoSliceMut<'a> {
10841084 /// Also see [`IoSliceMut::advance_slices`] to advance the cursors of
10851085 /// multiple buffers.
10861086 ///
1087+ /// # Panics
1088+ ///
1089+ /// Panics when trying to advance beyond the end of the slice.
1090+ ///
10871091 /// # Examples
10881092 ///
10891093 /// ```
@@ -1105,15 +1109,18 @@ impl<'a> IoSliceMut<'a> {
11051109 self . 0 . advance ( n)
11061110 }
11071111
1108- /// Advance the internal cursor of the slices.
1112+ /// Advance a slice of slices.
11091113 ///
1110- /// # Notes
1114+ /// Shrinks the slice to remove any `IoSliceMut`s that are fully advanced over.
1115+ /// If the cursor ends up in the middle of an `IoSliceMut`, it is modified
1116+ /// to start at that cursor.
11111117 ///
1112- /// Elements in the slice may be modified if the cursor is not advanced to
1113- /// the end of the slice. For example if we have a slice of buffers with 2
1114- /// `IoSliceMut`s, both of length 8, and we advance the cursor by 10 bytes
1115- /// the first `IoSliceMut` will be untouched however the second will be
1116- /// modified to remove the first 2 bytes (10 - 8).
1118+ /// For example, if we have a slice of two 8-byte `IoSliceMut`s, and we advance by 10 bytes,
1119+ /// the result will only include the second `IoSliceMut`, advanced by 2 bytes.
1120+ ///
1121+ /// # Panics
1122+ ///
1123+ /// Panics when trying to advance beyond the end of the slices.
11171124 ///
11181125 /// # Examples
11191126 ///
@@ -1154,7 +1161,9 @@ impl<'a> IoSliceMut<'a> {
11541161 }
11551162
11561163 * bufs = & mut replace ( bufs, & mut [ ] ) [ remove..] ;
1157- if !bufs. is_empty ( ) {
1164+ if bufs. is_empty ( ) {
1165+ assert ! ( n == accumulated_len, "advancing io slices beyond their length" ) ;
1166+ } else {
11581167 bufs[ 0 ] . advance ( n - accumulated_len)
11591168 }
11601169 }
@@ -1219,6 +1228,10 @@ impl<'a> IoSlice<'a> {
12191228 /// Also see [`IoSlice::advance_slices`] to advance the cursors of multiple
12201229 /// buffers.
12211230 ///
1231+ /// # Panics
1232+ ///
1233+ /// Panics when trying to advance beyond the end of the slice.
1234+ ///
12221235 /// # Examples
12231236 ///
12241237 /// ```
@@ -1240,15 +1253,18 @@ impl<'a> IoSlice<'a> {
12401253 self . 0 . advance ( n)
12411254 }
12421255
1243- /// Advance the internal cursor of the slices.
1256+ /// Advance a slice of slices.
12441257 ///
1245- /// # Notes
1258+ /// Shrinks the slice to remove any `IoSlice`s that are fully advanced over.
1259+ /// If the cursor ends up in the middle of an `IoSlice`, it is modified
1260+ /// to start at that cursor.
12461261 ///
1247- /// Elements in the slice may be modified if the cursor is not advanced to
1248- /// the end of the slice. For example if we have a slice of buffers with 2
1249- /// `IoSlice`s, both of length 8, and we advance the cursor by 10 bytes the
1250- /// first `IoSlice` will be untouched however the second will be modified to
1251- /// remove the first 2 bytes (10 - 8).
1262+ /// For example, if we have a slice of two 8-byte `IoSlice`s, and we advance by 10 bytes,
1263+ /// the result will only include the second `IoSlice`, advanced by 2 bytes.
1264+ ///
1265+ /// # Panics
1266+ ///
1267+ /// Panics when trying to advance beyond the end of the slices.
12521268 ///
12531269 /// # Examples
12541270 ///
@@ -1288,7 +1304,9 @@ impl<'a> IoSlice<'a> {
12881304 }
12891305
12901306 * bufs = & mut replace ( bufs, & mut [ ] ) [ remove..] ;
1291- if !bufs. is_empty ( ) {
1307+ if bufs. is_empty ( ) {
1308+ assert ! ( n == accumulated_len, "advancing io slices beyond their length" ) ;
1309+ } else {
12921310 bufs[ 0 ] . advance ( n - accumulated_len)
12931311 }
12941312 }
0 commit comments