Skip to content

Commit

Permalink
Rollup merge of rust-lang#100337 - camelid:stabilize-io_read_to_strin…
Browse files Browse the repository at this point in the history
…g, r=JohnTitor

Stabilize `std::io::read_to_string`

Closes rust-lang#80218. 🎉

This PR stabilizes the `std::io::read_to_string` function, with the following public API:

```rust
pub fn read_to_string<R: Read>(reader: R) -> Result<String>;
```

It's analogous to `std::fs::read_to_string` for files, but it works on anything that implements `io::Read`, including `io::stdin()`.

See the tracking issue (rust-lang#80218) or documentation for details.
  • Loading branch information
matthiaskrgr authored Aug 28, 2022
2 parents 049c73e + c04568b commit b87b660
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,6 @@ pub trait Read {
/// # Examples
///
/// ```no_run
/// #![feature(io_read_to_string)]
///
/// # use std::io;
/// fn main() -> io::Result<()> {
/// let stdin = io::read_to_string(io::stdin())?;
Expand All @@ -1042,7 +1040,7 @@ pub trait Read {
/// Ok(())
/// }
/// ```
#[unstable(feature = "io_read_to_string", issue = "80218")]
#[stable(feature = "io_read_to_string", since = "1.65.0")]
pub fn read_to_string<R: Read>(mut reader: R) -> Result<String> {
let mut buf = String::new();
reader.read_to_string(&mut buf)?;
Expand Down

0 comments on commit b87b660

Please sign in to comment.