Commit a623c52 1 parent 332cc8f commit a623c52 Copy full SHA for a623c52
File tree 7 files changed +60
-7
lines changed
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> {
1167
1167
bufs[ 0 ] . advance ( n - accumulated_len)
1168
1168
}
1169
1169
}
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
+ }
1170
1177
}
1171
1178
1172
1179
#[ stable( feature = "iovec" , since = "1.36.0" ) ]
@@ -1310,6 +1317,13 @@ impl<'a> IoSlice<'a> {
1310
1317
bufs[ 0 ] . advance ( n - accumulated_len)
1311
1318
}
1312
1319
}
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
+ }
1313
1327
}
1314
1328
1315
1329
#[ 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() {
480
480
assert ! ( bufs. is_empty( ) ) ;
481
481
}
482
482
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
+
483
497
/// Create a new writer that reads from at most `n_bufs` and reads
484
498
/// `per_call` bytes (in total) per call to write.
485
499
fn 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> {
33
33
}
34
34
35
35
#[ inline]
36
- pub fn as_slice ( & self ) -> & [ u8 ] {
36
+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
37
37
unsafe { slice:: from_raw_parts ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
38
38
}
39
39
}
@@ -66,12 +66,17 @@ impl<'a> IoSliceMut<'a> {
66
66
}
67
67
68
68
#[ inline]
69
- pub fn as_slice ( & self ) -> & [ u8 ] {
69
+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
70
70
unsafe { slice:: from_raw_parts ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
71
71
}
72
72
73
73
#[ 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 ] {
75
80
unsafe { slice:: from_raw_parts_mut ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
76
81
}
77
82
}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ impl<'a> IoSlice<'a> {
32
32
}
33
33
34
34
#[ inline]
35
- pub fn as_slice ( & self ) -> & [ u8 ] {
35
+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
36
36
unsafe { slice:: from_raw_parts ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
37
37
}
38
38
}
@@ -73,4 +73,9 @@ impl<'a> IoSliceMut<'a> {
73
73
pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
74
74
unsafe { slice:: from_raw_parts_mut ( self . vec . iov_base as * mut u8 , self . vec . iov_len ) }
75
75
}
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
+ }
76
81
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ impl<'a> IoSlice<'a> {
15
15
}
16
16
17
17
#[ inline]
18
- pub fn as_slice ( & self ) -> & [ u8 ] {
18
+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
19
19
self . 0
20
20
}
21
21
}
@@ -44,4 +44,9 @@ impl<'a> IoSliceMut<'a> {
44
44
pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
45
45
self . 0
46
46
}
47
+
48
+ #[ inline]
49
+ pub fn into_slice ( self ) -> & ' a mut [ u8 ] {
50
+ self . 0
51
+ }
47
52
}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ impl<'a> IoSlice<'a> {
29
29
}
30
30
31
31
#[ inline]
32
- pub fn as_slice ( & self ) -> & [ u8 ] {
32
+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
33
33
unsafe { slice:: from_raw_parts ( self . vec . buf as * const u8 , self . vec . buf_len ) }
34
34
}
35
35
}
@@ -70,4 +70,9 @@ impl<'a> IoSliceMut<'a> {
70
70
pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
71
71
unsafe { slice:: from_raw_parts_mut ( self . vec . buf as * mut u8 , self . vec . buf_len ) }
72
72
}
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
+ }
73
78
}
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ impl<'a> IoSlice<'a> {
35
35
}
36
36
37
37
#[ inline]
38
- pub fn as_slice ( & self ) -> & [ u8 ] {
38
+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
39
39
unsafe { slice:: from_raw_parts ( self . vec . buf as * mut u8 , self . vec . len as usize ) }
40
40
}
41
41
}
@@ -77,4 +77,9 @@ impl<'a> IoSliceMut<'a> {
77
77
pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
78
78
unsafe { slice:: from_raw_parts_mut ( self . vec . buf as * mut u8 , self . vec . len as usize ) }
79
79
}
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
+ }
80
85
}
You can’t perform that action at this time.
0 commit comments