Skip to content

Commit aa0ce4a

Browse files
committed
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]: #80218 (comment)
1 parent 124555a commit aa0ce4a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/std/src/io/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1031,14 +1031,14 @@ pub trait Read {
10311031
///
10321032
/// # use std::io;
10331033
/// fn main() -> io::Result<()> {
1034-
/// let stdin = io::read_to_string(&mut io::stdin())?;
1034+
/// let stdin = io::read_to_string(io::stdin())?;
10351035
/// println!("Stdin was:");
10361036
/// println!("{}", stdin);
10371037
/// Ok(())
10381038
/// }
10391039
/// ```
10401040
#[unstable(feature = "io_read_to_string", issue = "80218")]
1041-
pub fn read_to_string<R: Read>(reader: &mut R) -> Result<String> {
1041+
pub fn read_to_string<R: Read>(mut reader: R) -> Result<String> {
10421042
let mut buf = String::new();
10431043
reader.read_to_string(&mut buf)?;
10441044
Ok(buf)

0 commit comments

Comments
 (0)