File tree Expand file tree Collapse file tree 7 files changed +60
-7
lines changed Expand file tree Collapse file tree 7 files changed +60
-7
lines changed Original file line number Diff line number Diff line change @@ -1167,6 +1167,13 @@ impl<'a> IoSliceMut<'a> {
11671167 bufs[ 0 ] . advance ( n - accumulated_len)
11681168 }
11691169 }
1170+
1171+ /// Returns the slice this `IoSlice` was originally created with.
1172+ #[ unstable( feature = "io_slice_cast" , issue = "none" ) ]
1173+ #[ inline]
1174+ pub fn into_slice ( self ) -> & ' a mut [ u8 ] {
1175+ self . 0 . into_slice ( )
1176+ }
11701177}
11711178
11721179#[ stable( feature = "iovec" , since = "1.36.0" ) ]
@@ -1310,6 +1317,13 @@ impl<'a> IoSlice<'a> {
13101317 bufs[ 0 ] . advance ( n - accumulated_len)
13111318 }
13121319 }
1320+
1321+ /// Returns the slice this `IoSlice` was originally created with.
1322+ #[ unstable( feature = "io_slice_cast" , issue = "none" ) ]
1323+ #[ inline]
1324+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
1325+ self . 0 . as_slice ( )
1326+ }
13131327}
13141328
13151329#[ stable( feature = "iovec" , since = "1.36.0" ) ]
Original file line number Diff line number Diff line change @@ -480,6 +480,20 @@ fn io_slice_advance_slices_beyond_total_length() {
480480 assert ! ( bufs. is_empty( ) ) ;
481481}
482482
483+ #[ test]
484+ fn io_slice_as_slice ( ) {
485+ let buf = [ 1 ; 8 ] ;
486+ let slice = IoSlice :: new ( & buf) . as_slice ( ) ;
487+ assert_eq ! ( slice, buf) ;
488+ }
489+
490+ #[ test]
491+ fn io_slice_into_slice ( ) {
492+ let mut buf = [ 1 ; 8 ] ;
493+ let slice = IoSliceMut :: new ( & mut buf) . into_slice ( ) ;
494+ assert_eq ! ( slice, [ 1 ; 8 ] ) ;
495+ }
496+
483497/// Create a new writer that reads from at most `n_bufs` and reads
484498/// `per_call` bytes (in total) per call to write.
485499fn test_writer ( n_bufs : usize , per_call : usize ) -> TestWriter {
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ impl<'a> IoSlice<'a> {
3333 }
3434
3535 #[ inline]
36- pub fn as_slice ( & self ) -> & [ u8 ] {
36+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
3737 unsafe { slice:: from_raw_parts ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
3838 }
3939}
@@ -66,12 +66,17 @@ impl<'a> IoSliceMut<'a> {
6666 }
6767
6868 #[ inline]
69- pub fn as_slice ( & self ) -> & [ u8 ] {
69+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
7070 unsafe { slice:: from_raw_parts ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
7171 }
7272
7373 #[ inline]
74- pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
74+ pub fn as_mut_slice ( & mut self ) -> & ' a mut [ u8 ] {
75+ unsafe { slice:: from_raw_parts_mut ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
76+ }
77+
78+ #[ inline]
79+ pub fn into_slice ( self ) -> & ' a mut [ u8 ] {
7580 unsafe { slice:: from_raw_parts_mut ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
7681 }
7782}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ impl<'a> IoSlice<'a> {
3232 }
3333
3434 #[ inline]
35- pub fn as_slice ( & self ) -> & [ u8 ] {
35+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
3636 unsafe { slice:: from_raw_parts ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
3737 }
3838}
@@ -73,4 +73,9 @@ impl<'a> IoSliceMut<'a> {
7373 pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
7474 unsafe { slice:: from_raw_parts_mut ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
7575 }
76+
77+ #[ inline]
78+ pub fn into_slice ( self ) -> & ' a mut [ u8 ] {
79+ unsafe { slice:: from_raw_parts_mut ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
80+ }
7681}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ impl<'a> IoSlice<'a> {
1515 }
1616
1717 #[ inline]
18- pub fn as_slice ( & self ) -> & [ u8 ] {
18+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
1919 self . 0
2020 }
2121}
@@ -44,4 +44,9 @@ impl<'a> IoSliceMut<'a> {
4444 pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
4545 self . 0
4646 }
47+
48+ #[ inline]
49+ pub fn into_slice ( self ) -> & ' a mut [ u8 ] {
50+ self . 0
51+ }
4752}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ impl<'a> IoSlice<'a> {
2929 }
3030
3131 #[ inline]
32- pub fn as_slice ( & self ) -> & [ u8 ] {
32+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
3333 unsafe { slice:: from_raw_parts ( self . vec . buf as * const u8 , self . vec . buf_len ) }
3434 }
3535}
@@ -70,4 +70,9 @@ impl<'a> IoSliceMut<'a> {
7070 pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
7171 unsafe { slice:: from_raw_parts_mut ( self . vec . buf as * mut u8 , self . vec . buf_len ) }
7272 }
73+
74+ #[ inline]
75+ pub fn into_slice ( self ) -> & ' a mut [ u8 ] {
76+ unsafe { slice:: from_raw_parts_mut ( self . vec . buf as * mut u8 , self . vec . buf_len ) }
77+ }
7378}
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ impl<'a> IoSlice<'a> {
3535 }
3636
3737 #[ inline]
38- pub fn as_slice ( & self ) -> & [ u8 ] {
38+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
3939 unsafe { slice:: from_raw_parts ( self . vec . buf as * mut u8 , self . vec . len as usize ) }
4040 }
4141}
@@ -77,4 +77,9 @@ impl<'a> IoSliceMut<'a> {
7777 pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
7878 unsafe { slice:: from_raw_parts_mut ( self . vec . buf as * mut u8 , self . vec . len as usize ) }
7979 }
80+
81+ #[ inline]
82+ pub fn into_slice ( self ) -> & ' a mut [ u8 ] {
83+ unsafe { slice:: from_raw_parts_mut ( self . vec . buf as * mut u8 , self . vec . len as usize ) }
84+ }
8085}
You can’t perform that action at this time.
0 commit comments