@@ -1340,6 +1340,25 @@ impl<'a> IoSliceMut<'a> {
1340
1340
bufs[ 0 ] . advance ( left) ;
1341
1341
}
1342
1342
}
1343
+
1344
+ /// Get the underlying bytes as a mutable slice with the original lifetime.
1345
+ ///
1346
+ /// # Examples
1347
+ ///
1348
+ /// ```
1349
+ /// #![feature(io_slice_as_bytes)]
1350
+ /// use std::io::IoSliceMut;
1351
+ ///
1352
+ /// let mut data = *b"abcdef";
1353
+ /// let io_slice = IoSliceMut::new(&mut data);
1354
+ /// io_slice.into_slice()[0] = b'A';
1355
+ ///
1356
+ /// assert_eq!(&data, b"Abcdef");
1357
+ /// ```
1358
+ #[ unstable( feature = "io_slice_as_bytes" , issue = "111277" ) ]
1359
+ pub const fn into_slice ( self ) -> & ' a mut [ u8 ] {
1360
+ self . 0 . into_slice ( )
1361
+ }
1343
1362
}
1344
1363
1345
1364
#[ stable( feature = "iovec" , since = "1.36.0" ) ]
@@ -1482,6 +1501,32 @@ impl<'a> IoSlice<'a> {
1482
1501
bufs[ 0 ] . advance ( left) ;
1483
1502
}
1484
1503
}
1504
+
1505
+ /// Get the underlying bytes as a slice with the original lifetime.
1506
+ ///
1507
+ /// This doesn't borrow from `self`, so is less restrictive than calling
1508
+ /// `.deref()`, which does.
1509
+ ///
1510
+ /// # Examples
1511
+ ///
1512
+ /// ```
1513
+ /// #![feature(io_slice_as_bytes)]
1514
+ /// use std::io::IoSlice;
1515
+ ///
1516
+ /// let data = b"abcdef";
1517
+ ///
1518
+ /// let mut io_slice = IoSlice::new(data);
1519
+ /// let tail = &io_slice.as_slice()[3..];
1520
+ ///
1521
+ /// // This works because `tail` doesn't borrow `io_slice`
1522
+ /// io_slice = IoSlice::new(tail);
1523
+ ///
1524
+ /// assert_eq!(io_slice.as_slice(), b"def");
1525
+ /// ```
1526
+ #[ unstable( feature = "io_slice_as_bytes" , issue = "111277" ) ]
1527
+ pub const fn as_slice ( self ) -> & ' a [ u8 ] {
1528
+ self . 0 . as_slice ( )
1529
+ }
1485
1530
}
1486
1531
1487
1532
#[ stable( feature = "iovec" , since = "1.36.0" ) ]
0 commit comments