@@ -1377,7 +1377,7 @@ pub trait Write {
13771377 Ok ( ( ) )
13781378 }
13791379
1380- /// Attempts to write an multiple buffers into this writer.
1380+ /// Attempts to write multiple buffers into this writer.
13811381 ///
13821382 /// This method will continuously call [`write_vectored`] until there is no
13831383 /// more data to be written or an error of non-[`ErrorKind::Interrupted`]
@@ -1393,16 +1393,17 @@ pub trait Write {
13931393 ///
13941394 /// # Notes
13951395 ///
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.
13991396 ///
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.
14061407 ///
14071408 /// # Examples
14081409 ///
@@ -1432,7 +1433,7 @@ pub trait Write {
14321433 Ok ( 0 ) => {
14331434 return Err ( Error :: new ( ErrorKind :: WriteZero , "failed to write whole buffer" ) ) ;
14341435 }
1435- Ok ( n) => bufs = IoSlice :: advance ( mem:: replace ( & mut bufs, & mut [ ] ) , n) ,
1436+ Ok ( n) => bufs = IoSlice :: advance ( mem:: take ( & mut bufs) , n) ,
14361437 Err ( ref e) if e. kind ( ) == ErrorKind :: Interrupted => { }
14371438 Err ( e) => return Err ( e) ,
14381439 }
@@ -2956,11 +2957,16 @@ mod tests {
29562957 ( vec![ IoSlice :: new( & [ 1 , 2 , 3 , 4 ] ) ] , & [ 1 , 2 , 3 , 4 ] ) ,
29572958 ( vec![ IoSlice :: new( & [ 1 , 2 , 3 , 4 , 5 ] ) ] , & [ 1 , 2 , 3 , 4 , 5 ] ) ,
29582959 ( vec![ IoSlice :: new( & [ 1 ] ) , IoSlice :: new( & [ 2 ] ) ] , & [ 1 , 2 ] ) ,
2960+ ( vec![ IoSlice :: new( & [ 1 ] ) , IoSlice :: new( & [ 2 , 2 ] ) ] , & [ 1 , 2 , 2 ] ) ,
29592961 ( 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 ] ) ,
29602964 ( 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 ] ) ,
29612966 ( vec![ IoSlice :: new( & [ 1 , 1 , 1 , 1 ] ) , IoSlice :: new( & [ 2 , 2 , 2 , 2 ] ) ] , & [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ] ) ,
29622967 ( vec![ IoSlice :: new( & [ 1 ] ) , IoSlice :: new( & [ 2 ] ) , IoSlice :: new( & [ 3 ] ) ] , & [ 1 , 2 , 3 ] ) ,
29632968 ( 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 ] ) ,
29642970 ( 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 ] ) ,
29652971 ] ;
29662972
0 commit comments