From aa0ce4a20ee54eba911f2225644db768f6cad7ec Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Thu, 13 Jan 2022 10:48:07 -0800 Subject: [PATCH] Remove `&mut` from `io::read_to_string` signature `@m-ou-se` [realized][1] that because `Read` is implemented for `&mut impl Read`, there's no need to take `&mut` in `io::read_to_string`. Removing the `&mut` from the signature allows users to remove the `&mut` from their calls (and thus pass an owned reader) if they don't use the reader later. [1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129 --- library/std/src/io/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 358ef22e708d7..824938ce38e68 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -1031,14 +1031,14 @@ pub trait Read { /// /// # use std::io; /// fn main() -> io::Result<()> { -/// let stdin = io::read_to_string(&mut io::stdin())?; +/// let stdin = io::read_to_string(io::stdin())?; /// println!("Stdin was:"); /// println!("{}", stdin); /// Ok(()) /// } /// ``` #[unstable(feature = "io_read_to_string", issue = "80218")] -pub fn read_to_string(reader: &mut R) -> Result { +pub fn read_to_string(mut reader: R) -> Result { let mut buf = String::new(); reader.read_to_string(&mut buf)?; Ok(buf)