@@ -1522,6 +1522,18 @@ impl<T: BufRead> BufRead for Take<T> {
1522
1522
}
1523
1523
}
1524
1524
1525
+ fn read_one_byte ( reader : & mut Read ) -> Option < Result < u8 > > {
1526
+ let mut buf = [ 0 ] ;
1527
+ loop {
1528
+ return match reader. read ( & mut buf) {
1529
+ Ok ( 0 ) => None ,
1530
+ Ok ( ..) => Some ( Ok ( buf[ 0 ] ) ) ,
1531
+ Err ( ref e) if e. kind ( ) == ErrorKind :: Interrupted => continue ,
1532
+ Err ( e) => Some ( Err ( e) ) ,
1533
+ } ;
1534
+ }
1535
+ }
1536
+
1525
1537
/// An iterator over `u8` values of a reader.
1526
1538
///
1527
1539
/// This struct is generally created by calling [`bytes()`][bytes] on a reader.
@@ -1538,12 +1550,7 @@ impl<R: Read> Iterator for Bytes<R> {
1538
1550
type Item = Result < u8 > ;
1539
1551
1540
1552
fn next ( & mut self ) -> Option < Result < u8 > > {
1541
- let mut buf = [ 0 ] ;
1542
- match self . inner . read ( & mut buf) {
1543
- Ok ( 0 ) => None ,
1544
- Ok ( ..) => Some ( Ok ( buf[ 0 ] ) ) ,
1545
- Err ( e) => Some ( Err ( e) ) ,
1546
- }
1553
+ read_one_byte ( & mut self . inner )
1547
1554
}
1548
1555
}
1549
1556
@@ -1579,11 +1586,10 @@ impl<R: Read> Iterator for Chars<R> {
1579
1586
type Item = result:: Result < char , CharsError > ;
1580
1587
1581
1588
fn next ( & mut self ) -> Option < result:: Result < char , CharsError > > {
1582
- let mut buf = [ 0 ] ;
1583
- let first_byte = match self . inner . read ( & mut buf) {
1584
- Ok ( 0 ) => return None ,
1585
- Ok ( ..) => buf[ 0 ] ,
1586
- Err ( e) => return Some ( Err ( CharsError :: Other ( e) ) ) ,
1589
+ let first_byte = match read_one_byte ( & mut self . inner ) {
1590
+ None => return None ,
1591
+ Some ( Ok ( b) ) => b,
1592
+ Some ( Err ( e) ) => return Some ( Err ( CharsError :: Other ( e) ) ) ,
1587
1593
} ;
1588
1594
let width = core_str:: utf8_char_width ( first_byte) ;
1589
1595
if width == 1 { return Some ( Ok ( first_byte as char ) ) }
@@ -1595,6 +1601,7 @@ impl<R: Read> Iterator for Chars<R> {
1595
1601
match self . inner . read ( & mut buf[ start..width] ) {
1596
1602
Ok ( 0 ) => return Some ( Err ( CharsError :: NotUtf8 ) ) ,
1597
1603
Ok ( n) => start += n,
1604
+ Err ( ref e) if e. kind ( ) == ErrorKind :: Interrupted => continue ,
1598
1605
Err ( e) => return Some ( Err ( CharsError :: Other ( e) ) ) ,
1599
1606
}
1600
1607
}
0 commit comments