diff options
| author | Camelid <camelidcamel@gmail.com> | 2021-01-11 19:17:13 -0800 |
|---|---|---|
| committer | Camelid <camelidcamel@gmail.com> | 2021-01-11 19:18:39 -0800 |
| commit | 746329201546d38875bf1a7fa232453e833c01eb (patch) | |
| tree | b210588196cd067be4a90ed2da3c1feea4dcee97 /library/std/src | |
| parent | 588786a788a5606dd3f4b4769ecd2e0c26a3ad20 (diff) | |
| download | rust-746329201546d38875bf1a7fa232453e833c01eb.tar.gz rust-746329201546d38875bf1a7fa232453e833c01eb.zip | |
Add docs on performance
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/io/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index fdc0198945e..5540891c646 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -953,6 +953,19 @@ pub trait Read { /// use [`Read::read_to_string`] you have to remember to check whether the read /// succeeded because otherwise your buffer will be empty or only partially full.) /// +/// # Performance +/// +/// The downside of this function's increased ease of use and type safety is +/// that it gives you less control over performance. For example, you can't +/// pre-allocate memory like you can using [`String::with_capacity`] and +/// [`Read::read_to_string`]. Also, you can't re-use the buffer if an error +/// occurs while reading. +/// +/// In many cases, this function's performance will be adequate and the ease of use +/// and type safety tradeoffs will be worth it. However, there are cases where you +/// need more control over performance, and in those cases you should definitely use +/// [`Read::read_to_string`] directly. +/// /// # Errors /// /// This function forces you to handle errors because the output (the `String`) |
