@@ -264,6 +264,7 @@ use fmt;
264264use slice;
265265use str;
266266use memchr;
267+ use ops:: { Deref , DerefMut } ;
267268use ptr;
268269use sys;
269270
@@ -531,7 +532,7 @@ pub trait Read {
531532 /// `read`.
532533 #[ unstable( feature = "iovec" , issue = "0" ) ]
533534 fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> Result < usize > {
534- match bufs. iter_mut ( ) . map ( |b| b . as_mut_slice ( ) ) . find ( |b| !b. is_empty ( ) ) {
535+ match bufs. iter_mut ( ) . find ( |b| !b. is_empty ( ) ) {
535536 Some ( buf) => self . read ( buf) ,
536537 None => Ok ( 0 ) ,
537538 }
@@ -896,7 +897,7 @@ pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>);
896897#[ unstable( feature = "iovec" , issue = "0" ) ]
897898impl < ' a > fmt:: Debug for IoVecMut < ' a > {
898899 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
899- fmt:: Debug :: fmt ( self . as_slice ( ) , fmt)
900+ fmt:: Debug :: fmt ( self . 0 . as_slice ( ) , fmt)
900901 }
901902}
902903
@@ -911,18 +912,22 @@ impl<'a> IoVecMut<'a> {
911912 pub fn new ( buf : & ' a mut [ u8 ] ) -> IoVecMut < ' a > {
912913 IoVecMut ( sys:: io:: IoVecMut :: new ( buf) )
913914 }
915+ }
916+
917+ #[ unstable( feature = "iovec" , issue = "0" ) ]
918+ impl < ' a > Deref for IoVecMut < ' a > {
919+ type Target = [ u8 ] ;
914920
915- /// Returns a shared reference to the inner slice.
916- #[ unstable( feature = "iovec" , issue = "0" ) ]
917921 #[ inline]
918- pub fn as_slice ( & self ) -> & ' a [ u8 ] {
922+ fn deref ( & self ) -> & [ u8 ] {
919923 self . 0 . as_slice ( )
920924 }
925+ }
921926
922- /// Returns a mutable reference to the inner slice.
923- # [ unstable ( feature = "iovec" , issue = "0" ) ]
927+ # [ unstable ( feature = "iovec" , issue = "0" ) ]
928+ impl < ' a > DerefMut for IoVecMut < ' a > {
924929 #[ inline]
925- pub fn as_mut_slice ( & mut self ) -> & ' a mut [ u8 ] {
930+ fn deref_mut ( & mut self ) -> & mut [ u8 ] {
926931 self . 0 . as_mut_slice ( )
927932 }
928933}
@@ -939,7 +944,7 @@ pub struct IoVec<'a>(sys::io::IoVec<'a>);
939944#[ unstable( feature = "iovec" , issue = "0" ) ]
940945impl < ' a > fmt:: Debug for IoVec < ' a > {
941946 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
942- fmt:: Debug :: fmt ( self . as_slice ( ) , fmt)
947+ fmt:: Debug :: fmt ( self . 0 . as_slice ( ) , fmt)
943948 }
944949}
945950
@@ -954,11 +959,14 @@ impl<'a> IoVec<'a> {
954959 pub fn new ( buf : & ' a [ u8 ] ) -> IoVec < ' a > {
955960 IoVec ( sys:: io:: IoVec :: new ( buf) )
956961 }
962+ }
963+
964+ #[ unstable( feature = "iovec" , issue = "0" ) ]
965+ impl < ' a > Deref for IoVec < ' a > {
966+ type Target = [ u8 ] ;
957967
958- /// Returns a shared reference to the inner slice.
959- #[ unstable( feature = "iovec" , issue = "0" ) ]
960968 #[ inline]
961- pub fn as_slice ( & self ) -> & ' a [ u8 ] {
969+ fn deref ( & self ) -> & [ u8 ] {
962970 self . 0 . as_slice ( )
963971 }
964972}
@@ -1103,7 +1111,7 @@ pub trait Write {
11031111 /// `write`.
11041112 #[ unstable( feature = "iovec" , issue = "0" ) ]
11051113 fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> Result < usize > {
1106- match bufs. iter ( ) . map ( |b| b . as_slice ( ) ) . find ( |b| !b. is_empty ( ) ) {
1114+ match bufs. iter ( ) . find ( |b| !b. is_empty ( ) ) {
11071115 Some ( buf) => self . write ( buf) ,
11081116 None => Ok ( 0 ) ,
11091117 }
@@ -1813,7 +1821,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
18131821 fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> Result < usize > {
18141822 if !self . done_first {
18151823 match self . first . read_vectored ( bufs) ? {
1816- 0 if bufs. iter ( ) . any ( |b| !b. as_slice ( ) . is_empty ( ) ) => self . done_first = true ,
1824+ 0 if bufs. iter ( ) . any ( |b| !b. is_empty ( ) ) => self . done_first = true ,
18171825 n => return Ok ( n) ,
18181826 }
18191827 }
0 commit comments