File tree Expand file tree Collapse file tree 6 files changed +28
-4
lines changed Expand file tree Collapse file tree 6 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -1491,6 +1491,30 @@ impl<'a> IoSlice<'a> {
1491
1491
bufs[ 0 ] . advance ( left) ;
1492
1492
}
1493
1493
}
1494
+
1495
+ /// Get the underlying bytes as a rust slice with the original lifetime
1496
+ ///
1497
+ /// # Example
1498
+ ///
1499
+ /// ```
1500
+ /// use std::io::IoSlice;
1501
+ ///
1502
+ /// let data = b"abcdef";
1503
+ ///
1504
+ /// let mut io_slice = IoSlice::new(data);
1505
+ /// let tail = io_slice.as_bytes()[3..];
1506
+ ///
1507
+ /// // This works because `tail` doesn't borrow `io_slice`
1508
+ /// io_slice = IoSlice::new(tail);
1509
+ ///
1510
+ /// assert_eq!(io_slice.as_bytes(), b"def");
1511
+ /// ```
1512
+ #[ unstable( feature = "io_slice_as_bytes" ) ]
1513
+ #[ inline]
1514
+ #[ must_use]
1515
+ pub const fn as_bytes ( & self ) -> & ' a [ u8 ] {
1516
+ self . 0 . as_slice ( )
1517
+ }
1494
1518
}
1495
1519
1496
1520
#[ 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 @@ -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 @@ -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 @@ -30,7 +30,7 @@ impl<'a> IoSlice<'a> {
30
30
}
31
31
32
32
#[ inline]
33
- pub fn as_slice ( & self ) -> & [ u8 ] {
33
+ pub fn as_slice ( & self ) -> & ' a [ u8 ] {
34
34
unsafe { slice:: from_raw_parts ( self . vec . buf as * const u8 , self . vec . buf_len ) }
35
35
}
36
36
}
You can’t perform that action at this time.
0 commit comments