@@ -466,6 +466,9 @@ pub trait Read {
466
466
/// variant will be returned. If an error is returned then it must be
467
467
/// guaranteed that no bytes were read.
468
468
///
469
+ /// An error of the `ErrorKind::Interrupted` kind is non-fatal and the read
470
+ /// operation should be retried if there is nothing else to do.
471
+ ///
469
472
/// # Examples
470
473
///
471
474
/// [`File`][file]s implement `Read`:
@@ -481,7 +484,7 @@ pub trait Read {
481
484
/// let mut f = File::open("foo.txt")?;
482
485
/// let mut buffer = [0; 10];
483
486
///
484
- /// // read 10 bytes
487
+ /// // read up to 10 bytes
485
488
/// f.read(&mut buffer[..])?;
486
489
/// # Ok(())
487
490
/// # }
@@ -885,6 +888,9 @@ pub trait Write {
885
888
/// It is **not** considered an error if the entire buffer could not be
886
889
/// written to this writer.
887
890
///
891
+ /// An error of the `ErrorKind::Interrupted` kind is non-fatal and the
892
+ /// write operation should be retried if there is nothing else to do.
893
+ ///
888
894
/// # Examples
889
895
///
890
896
/// ```
@@ -894,6 +900,7 @@ pub trait Write {
894
900
/// # fn foo() -> std::io::Result<()> {
895
901
/// let mut buffer = File::create("foo.txt")?;
896
902
///
903
+ /// // Writes some prefix of the byte string, not necessarily all of it.
897
904
/// buffer.write(b"some bytes")?;
898
905
/// # Ok(())
899
906
/// # }
@@ -929,14 +936,17 @@ pub trait Write {
929
936
930
937
/// Attempts to write an entire buffer into this write.
931
938
///
932
- /// This method will continuously call `write` while there is more data to
933
- /// write. This method will not return until the entire buffer has been
934
- /// successfully written or an error occurs. The first error generated from
935
- /// this method will be returned.
939
+ /// This method will continuously call `write` until there is no more data
940
+ /// to be written or an error of non-`ErrorKind::Interrupted` kind is
941
+ /// returned. This method will not return until the entire buffer has been
942
+ /// successfully written or such an error occurs. The first error that is
943
+ /// not of `ErrorKind::Interrupted` kind generated from this method will be
944
+ /// returned.
936
945
///
937
946
/// # Errors
938
947
///
939
- /// This function will return the first error that `write` returns.
948
+ /// This function will return the first error of
949
+ /// non-`ErrorKind::Interrupted` kind that `write` returns.
940
950
///
941
951
/// # Examples
942
952
///
@@ -1494,6 +1504,87 @@ pub struct Chain<T, U> {
1494
1504
done_first : bool ,
1495
1505
}
1496
1506
1507
+ impl < T , U > Chain < T , U > {
1508
+ /// Consumes the `Chain`, returning the wrapped readers.
1509
+ ///
1510
+ /// # Examples
1511
+ ///
1512
+ /// ```
1513
+ /// #![feature(more_io_inner_methods)]
1514
+ ///
1515
+ /// # use std::io;
1516
+ /// use std::io::prelude::*;
1517
+ /// use std::fs::File;
1518
+ ///
1519
+ /// # fn foo() -> io::Result<()> {
1520
+ /// let mut foo_file = File::open("foo.txt")?;
1521
+ /// let mut bar_file = File::open("bar.txt")?;
1522
+ ///
1523
+ /// let chain = foo_file.chain(bar_file);
1524
+ /// let (foo_file, bar_file) = chain.into_inner();
1525
+ /// # Ok(())
1526
+ /// # }
1527
+ /// ```
1528
+ #[ unstable( feature = "more_io_inner_methods" , issue="41519" ) ]
1529
+ pub fn into_inner ( self ) -> ( T , U ) {
1530
+ ( self . first , self . second )
1531
+ }
1532
+
1533
+ /// Gets references to the underlying readers in this `Chain`.
1534
+ ///
1535
+ /// # Examples
1536
+ ///
1537
+ /// ```
1538
+ /// #![feature(more_io_inner_methods)]
1539
+ ///
1540
+ /// # use std::io;
1541
+ /// use std::io::prelude::*;
1542
+ /// use std::fs::File;
1543
+ ///
1544
+ /// # fn foo() -> io::Result<()> {
1545
+ /// let mut foo_file = File::open("foo.txt")?;
1546
+ /// let mut bar_file = File::open("bar.txt")?;
1547
+ ///
1548
+ /// let chain = foo_file.chain(bar_file);
1549
+ /// let (foo_file, bar_file) = chain.get_ref();
1550
+ /// # Ok(())
1551
+ /// # }
1552
+ /// ```
1553
+ #[ unstable( feature = "more_io_inner_methods" , issue="41519" ) ]
1554
+ pub fn get_ref ( & self ) -> ( & T , & U ) {
1555
+ ( & self . first , & self . second )
1556
+ }
1557
+
1558
+ /// Gets mutable references to the underlying readers in this `Chain`.
1559
+ ///
1560
+ /// Care should be taken to avoid modifying the internal I/O state of the
1561
+ /// underlying readers as doing so may corrupt the internal state of this
1562
+ /// `Chain`.
1563
+ ///
1564
+ /// # Examples
1565
+ ///
1566
+ /// ```
1567
+ /// #![feature(more_io_inner_methods)]
1568
+ ///
1569
+ /// # use std::io;
1570
+ /// use std::io::prelude::*;
1571
+ /// use std::fs::File;
1572
+ ///
1573
+ /// # fn foo() -> io::Result<()> {
1574
+ /// let mut foo_file = File::open("foo.txt")?;
1575
+ /// let mut bar_file = File::open("bar.txt")?;
1576
+ ///
1577
+ /// let mut chain = foo_file.chain(bar_file);
1578
+ /// let (foo_file, bar_file) = chain.get_mut();
1579
+ /// # Ok(())
1580
+ /// # }
1581
+ /// ```
1582
+ #[ unstable( feature = "more_io_inner_methods" , issue="41519" ) ]
1583
+ pub fn get_mut ( & mut self ) -> ( & mut T , & mut U ) {
1584
+ ( & mut self . first , & mut self . second )
1585
+ }
1586
+ }
1587
+
1497
1588
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
1498
1589
impl < T : fmt:: Debug , U : fmt:: Debug > fmt:: Debug for Chain < T , U > {
1499
1590
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -1606,6 +1697,64 @@ impl<T> Take<T> {
1606
1697
pub fn into_inner ( self ) -> T {
1607
1698
self . inner
1608
1699
}
1700
+
1701
+ /// Gets a reference to the underlying reader.
1702
+ ///
1703
+ /// # Examples
1704
+ ///
1705
+ /// ```
1706
+ /// #![feature(more_io_inner_methods)]
1707
+ ///
1708
+ /// use std::io;
1709
+ /// use std::io::prelude::*;
1710
+ /// use std::fs::File;
1711
+ ///
1712
+ /// # fn foo() -> io::Result<()> {
1713
+ /// let mut file = File::open("foo.txt")?;
1714
+ ///
1715
+ /// let mut buffer = [0; 5];
1716
+ /// let mut handle = file.take(5);
1717
+ /// handle.read(&mut buffer)?;
1718
+ ///
1719
+ /// let file = handle.get_ref();
1720
+ /// # Ok(())
1721
+ /// # }
1722
+ /// ```
1723
+ #[ unstable( feature = "more_io_inner_methods" , issue="41519" ) ]
1724
+ pub fn get_ref ( & self ) -> & T {
1725
+ & self . inner
1726
+ }
1727
+
1728
+ /// Gets a mutable reference to the underlying reader.
1729
+ ///
1730
+ /// Care should be taken to avoid modifying the internal I/O state of the
1731
+ /// underlying reader as doing so may corrupt the internal limit of this
1732
+ /// `Take`.
1733
+ ///
1734
+ /// # Examples
1735
+ ///
1736
+ /// ```
1737
+ /// #![feature(more_io_inner_methods)]
1738
+ ///
1739
+ /// use std::io;
1740
+ /// use std::io::prelude::*;
1741
+ /// use std::fs::File;
1742
+ ///
1743
+ /// # fn foo() -> io::Result<()> {
1744
+ /// let mut file = File::open("foo.txt")?;
1745
+ ///
1746
+ /// let mut buffer = [0; 5];
1747
+ /// let mut handle = file.take(5);
1748
+ /// handle.read(&mut buffer)?;
1749
+ ///
1750
+ /// let file = handle.get_mut();
1751
+ /// # Ok(())
1752
+ /// # }
1753
+ /// ```
1754
+ #[ unstable( feature = "more_io_inner_methods" , issue="41519" ) ]
1755
+ pub fn get_mut ( & mut self ) -> & mut T {
1756
+ & mut self . inner
1757
+ }
1609
1758
}
1610
1759
1611
1760
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments