@@ -1084,6 +1084,10 @@ impl<'a> IoSliceMut<'a> {
1084
1084
/// Also see [`IoSliceMut::advance_slices`] to advance the cursors of
1085
1085
/// multiple buffers.
1086
1086
///
1087
+ /// # Panics
1088
+ ///
1089
+ /// Panics when trying to advance beyond the end of the slice.
1090
+ ///
1087
1091
/// # Examples
1088
1092
///
1089
1093
/// ```
@@ -1105,15 +1109,18 @@ impl<'a> IoSliceMut<'a> {
1105
1109
self . 0 . advance ( n)
1106
1110
}
1107
1111
1108
- /// Advance the internal cursor of the slices.
1112
+ /// Advance a slice of slices.
1109
1113
///
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.
1111
1117
///
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.
1117
1124
///
1118
1125
/// # Examples
1119
1126
///
@@ -1154,7 +1161,9 @@ impl<'a> IoSliceMut<'a> {
1154
1161
}
1155
1162
1156
1163
* 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 {
1158
1167
bufs[ 0 ] . advance ( n - accumulated_len)
1159
1168
}
1160
1169
}
@@ -1219,6 +1228,10 @@ impl<'a> IoSlice<'a> {
1219
1228
/// Also see [`IoSlice::advance_slices`] to advance the cursors of multiple
1220
1229
/// buffers.
1221
1230
///
1231
+ /// # Panics
1232
+ ///
1233
+ /// Panics when trying to advance beyond the end of the slice.
1234
+ ///
1222
1235
/// # Examples
1223
1236
///
1224
1237
/// ```
@@ -1240,15 +1253,18 @@ impl<'a> IoSlice<'a> {
1240
1253
self . 0 . advance ( n)
1241
1254
}
1242
1255
1243
- /// Advance the internal cursor of the slices.
1256
+ /// Advance a slice of slices.
1244
1257
///
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.
1246
1261
///
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.
1252
1268
///
1253
1269
/// # Examples
1254
1270
///
@@ -1288,7 +1304,9 @@ impl<'a> IoSlice<'a> {
1288
1304
}
1289
1305
1290
1306
* 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 {
1292
1310
bufs[ 0 ] . advance ( n - accumulated_len)
1293
1311
}
1294
1312
}
0 commit comments