File tree Expand file tree Collapse file tree 6 files changed +29
-5
lines changed Expand file tree Collapse file tree 6 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -1292,6 +1292,30 @@ impl<'a> IoSlice<'a> {
1292
1292
bufs[ 0 ] . advance ( n - accumulated_len)
1293
1293
}
1294
1294
}
1295
+
1296
+ /// Get the underlying bytes as a rust slice with the original lifetime
1297
+ ///
1298
+ /// # Example
1299
+ ///
1300
+ /// ```
1301
+ /// use std::io::IoSlice;
1302
+ ///
1303
+ /// let data = b"abcdef";
1304
+ ///
1305
+ /// let mut io_slice = IoSlice::new(data);
1306
+ /// let tail = io_slice.as_bytes()[3..];
1307
+ ///
1308
+ /// // This works because `tail` doesn't borrow `io_slice`
1309
+ /// io_slice = IoSlice::new(tail);
1310
+ ///
1311
+ /// assert_eq!(io_slice.as_bytes(), b"def");
1312
+ /// ```
1313
+ #[ unstable( feature = "io_slice_as_bytes" ) ]
1314
+ #[ inline]
1315
+ #[ must_use]
1316
+ pub const fn as_bytes ( & self ) -> & ' a [ u8 ] {
1317
+ self . 0 . as_slice ( )
1318
+ }
1295
1319
}
1296
1320
1297
1321
#[ stable( feature = "iovec" , since = "1.36.0" ) ]
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
}
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
}
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
}
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
}
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
}
You can’t perform that action at this time.
0 commit comments