Skip to content

Commit 4d56e88

Browse files
authored
Update mod.rs
Small clarification on the usage of `read_to_string` and `read_to_end` trait methods.
1 parent 449c801 commit 4d56e88

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/std/src/io/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,13 @@ pub trait Read {
917917
/// # }
918918
/// ```
919919
///
920+
/// # Notes
921+
///
922+
/// Be careful using this trait method with streams that are expected to be continuous. For example, using
923+
/// `read_to_end` with streams like `stdin` will simply lock the application into waiting on the
924+
/// transmission of data to conclude. It is recommended you use this method if you know the stream will be closed
925+
/// at the other end. The problem is that EOF or End of File is never reached for streams that never close or are finite.
926+
///
920927
/// [`Vec::try_reserve`]: crate::vec::Vec::try_reserve
921928
#[stable(feature = "rust1", since = "1.0.0")]
922929
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
@@ -957,6 +964,13 @@ pub trait Read {
957964
/// }
958965
/// ```
959966
///
967+
/// # Notes
968+
///
969+
/// Be careful using this trait method with streams that are expected to be continuous. For example, using
970+
/// `read_to_string` with streams like `stdin` will simply lock the application into waiting on the
971+
/// transmission of data to conclude. It is recommended you use this method if you know the stream will be closed
972+
/// at the other end. The problem is that EOF or End of File is never reached for streams that never close or are finite.
973+
///
960974
/// (See also the [`std::fs::read_to_string`] convenience function for
961975
/// reading from a file.)
962976
///

0 commit comments

Comments
 (0)