@@ -1377,7 +1377,7 @@ pub trait Write {
1377
1377
Ok ( ( ) )
1378
1378
}
1379
1379
1380
- /// Attempts to write an multiple buffers into this writer.
1380
+ /// Attempts to write multiple buffers into this writer.
1381
1381
///
1382
1382
/// This method will continuously call [`write_vectored`] until there is no
1383
1383
/// more data to be written or an error of non-[`ErrorKind::Interrupted`]
@@ -1393,16 +1393,17 @@ pub trait Write {
1393
1393
///
1394
1394
/// # Notes
1395
1395
///
1396
- /// Different to `io::Write::write_vectored` this takes a *mutable*
1397
- /// reference to a slice of `IoSlice`s, not a non-mutable reference, because
1398
- /// we need to modify the slice to keep track of the bytes already written.
1399
1396
///
1400
- /// Once this function returns the contents of `bufs` is unspecified, as we
1401
- /// don't know what the contents of `bufs` will be as that depends on how
1402
- /// many writes we needed to do. We advice to see this function as taking
1403
- /// ownership of `bufs` and don't use the variable after the future returns.
1404
- /// The underlying buffers, to which `IoSlice` points (not the `IoSlice`
1405
- /// itself), are unchanged and can be reused.
1397
+ /// Unlike `io::Write::write_vectored`, this takes a *mutable* reference to
1398
+ /// a slice of `IoSlice`s, not an immutable one. That's because we need to
1399
+ /// modify the slice to keep track of the bytes already written.
1400
+ ///
1401
+ /// Once this function returns, the contents of `bufs` are unspecified, as
1402
+ /// this depends on how many calls to write_vectored were necessary. It is
1403
+ /// best to understand this function as taking ownership of `bufs` and to
1404
+ /// not use `bufs` afterwards. The underlying buffers, to which the
1405
+ /// `IoSlice`s point (but not the `IoSlice`s themselves), are unchanged and
1406
+ /// can be reused.
1406
1407
///
1407
1408
/// # Examples
1408
1409
///
@@ -1432,7 +1433,7 @@ pub trait Write {
1432
1433
Ok ( 0 ) => {
1433
1434
return Err ( Error :: new ( ErrorKind :: WriteZero , "failed to write whole buffer" ) ) ;
1434
1435
}
1435
- Ok ( n) => bufs = IoSlice :: advance ( mem:: replace ( & mut bufs, & mut [ ] ) , n) ,
1436
+ Ok ( n) => bufs = IoSlice :: advance ( mem:: take ( & mut bufs) , n) ,
1436
1437
Err ( ref e) if e. kind ( ) == ErrorKind :: Interrupted => { }
1437
1438
Err ( e) => return Err ( e) ,
1438
1439
}
@@ -2956,11 +2957,16 @@ mod tests {
2956
2957
( vec![ IoSlice :: new( & [ 1 , 2 , 3 , 4 ] ) ] , & [ 1 , 2 , 3 , 4 ] ) ,
2957
2958
( vec![ IoSlice :: new( & [ 1 , 2 , 3 , 4 , 5 ] ) ] , & [ 1 , 2 , 3 , 4 , 5 ] ) ,
2958
2959
( vec![ IoSlice :: new( & [ 1 ] ) , IoSlice :: new( & [ 2 ] ) ] , & [ 1 , 2 ] ) ,
2960
+ ( vec![ IoSlice :: new( & [ 1 ] ) , IoSlice :: new( & [ 2 , 2 ] ) ] , & [ 1 , 2 , 2 ] ) ,
2959
2961
( vec![ IoSlice :: new( & [ 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 ] ) ] , & [ 1 , 1 , 2 , 2 ] ) ,
2962
+ ( vec![ IoSlice :: new( & [ 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 , 2 ] ) ] , & [ 1 , 1 , 2 , 2 , 2 ] ) ,
2963
+ ( vec![ IoSlice :: new( & [ 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 , 2 ] ) ] , & [ 1 , 1 , 2 , 2 , 2 ] ) ,
2960
2964
( vec![ IoSlice :: new( & [ 1 , 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 , 2 ] ) ] , & [ 1 , 1 , 1 , 2 , 2 , 2 ] ) ,
2965
+ ( vec![ IoSlice :: new( & [ 1 , 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 , 2 , 2 ] ) ] , & [ 1 , 1 , 1 , 2 , 2 , 2 , 2 ] ) ,
2961
2966
( vec![ IoSlice :: new( & [ 1 , 1 , 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 , 2 , 2 ] ) ] , & [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ] ) ,
2962
2967
( vec![ IoSlice :: new( & [ 1 ] ) , IoSlice :: new( & [ 2 ] ) , IoSlice :: new( & [ 3 ] ) ] , & [ 1 , 2 , 3 ] ) ,
2963
2968
( vec![ IoSlice :: new( & [ 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 ] ) , IoSlice :: new( & [ 3 , 3 ] ) ] , & [ 1 , 1 , 2 , 2 , 3 , 3 ] ) ,
2969
+ ( vec![ IoSlice :: new( & [ 1 ] ) , IoSlice :: new( & [ 2 , 2 ] ) , IoSlice :: new( & [ 3 , 3 , 3 ] ) ] , & [ 1 , 2 , 2 , 3 , 3 , 3 ] ) ,
2964
2970
( vec![ IoSlice :: new( & [ 1 , 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 , 2 ] ) , IoSlice :: new( & [ 3 , 3 , 3 ] ) ] , & [ 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 ] ) ,
2965
2971
] ;
2966
2972
0 commit comments