@@ -2124,6 +2124,13 @@ where
2124
2124
/// The content of the IO stream is deserialized directly from the stream
2125
2125
/// without being buffered in memory by serde_json.
2126
2126
///
2127
+ /// When reading from a source against which short reads are not efficient, such
2128
+ /// as a [`File`], you will want to apply your own buffering because serde_json
2129
+ /// will not buffer the input. See [`std::io::BufReader`].
2130
+ ///
2131
+ /// [`File`]: https://doc.rust-lang.org/std/fs/struct.File.html
2132
+ /// [`BufReader`]: https://doc.rust-lang.org/std/io/struct.BufReader.html
2133
+ ///
2127
2134
/// # Example
2128
2135
///
2129
2136
/// ```rust
@@ -2135,6 +2142,7 @@ where
2135
2142
///
2136
2143
/// use std::error::Error;
2137
2144
/// use std::fs::File;
2145
+ /// use std::io::BufReader;
2138
2146
/// use std::path::Path;
2139
2147
///
2140
2148
/// #[derive(Deserialize, Debug)]
@@ -2144,11 +2152,12 @@ where
2144
2152
/// }
2145
2153
///
2146
2154
/// fn read_user_from_file<P: AsRef<Path>>(path: P) -> Result<User, Box<Error>> {
2147
- /// // Open the file in read-only mode.
2155
+ /// // Open the file in read-only mode with buffer .
2148
2156
/// let file = File::open(path)?;
2157
+ /// let reader = BufReader::new(file);
2149
2158
///
2150
2159
/// // Read the JSON contents of the file as an instance of `User`.
2151
- /// let u = serde_json::from_reader(file )?;
2160
+ /// let u = serde_json::from_reader(reader )?;
2152
2161
///
2153
2162
/// // Return the `User`.
2154
2163
/// Ok(u)
0 commit comments