Skip to content

Commit 7463292

Browse files
committed
Add docs on performance
1 parent 588786a commit 7463292

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/std/src/io/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,19 @@ pub trait Read {
953953
/// use [`Read::read_to_string`] you have to remember to check whether the read
954954
/// succeeded because otherwise your buffer will be empty or only partially full.)
955955
///
956+
/// # Performance
957+
///
958+
/// The downside of this function's increased ease of use and type safety is
959+
/// that it gives you less control over performance. For example, you can't
960+
/// pre-allocate memory like you can using [`String::with_capacity`] and
961+
/// [`Read::read_to_string`]. Also, you can't re-use the buffer if an error
962+
/// occurs while reading.
963+
///
964+
/// In many cases, this function's performance will be adequate and the ease of use
965+
/// and type safety tradeoffs will be worth it. However, there are cases where you
966+
/// need more control over performance, and in those cases you should definitely use
967+
/// [`Read::read_to_string`] directly.
968+
///
956969
/// # Errors
957970
///
958971
/// This function forces you to handle errors because the output (the `String`)

0 commit comments

Comments
 (0)