]> git.lizzy.rs Git - rust.git/commit
Add a `std::io::read_to_string` function
authorCamelid <camelidcamel@gmail.com>
Thu, 5 Nov 2020 08:44:42 +0000 (00:44 -0800)
committerCamelid <camelidcamel@gmail.com>
Sun, 20 Dec 2020 05:46:40 +0000 (21:46 -0800)
commit1f9a8a1620a677d668c981a8e6be3ce02ef06cd5
treef0fd43feb0e964af9c49031703495130bced0567
parent0c11b93f5a8914a40f619b0a1663baafe029d427
Add a `std::io::read_to_string` function

The equivalent of `std::fs::read_to_string`, but generalized to all
`Read` impls.

As the documentation on `std::io::read_to_string` says, the advantage of
this function is that it means you don't have to create a variable first
and it provides more type safety since you can only get the buffer out
if there were no errors. If you use `Read::read_to_string`, you have to
remember to check whether the read succeeded because otherwise your
buffer will be empty.

It's friendlier to newcomers and better in most cases to use an explicit
return value instead of an out parameter.
library/std/src/io/mod.rs