@@ -45,11 +45,17 @@ where
45
45
/// Create a JSON deserializer from one of the possible serde_json input
46
46
/// sources.
47
47
///
48
+ /// When reading from a source against which short reads are not efficient, such
49
+ /// as a [`File`], you will want to apply your own buffering because serde_json
50
+ /// will not buffer the input. See [`std::io::BufReader`].
51
+ ///
48
52
/// Typically it is more convenient to use one of these methods instead:
49
53
///
50
54
/// - Deserializer::from_str
51
55
/// - Deserializer::from_slice
52
56
/// - Deserializer::from_reader
57
+ ///
58
+ /// [`File`]: https://doc.rust-lang.org/std/fs/struct.File.html
53
59
pub fn new ( read : R ) -> Self {
54
60
Deserializer {
55
61
read,
@@ -2568,6 +2574,7 @@ where
2568
2574
///
2569
2575
/// use std::error::Error;
2570
2576
/// use std::net::{TcpListener, TcpStream};
2577
+ /// use std::io::BufReader;
2571
2578
///
2572
2579
/// #[derive(Deserialize, Debug)]
2573
2580
/// struct User {
@@ -2576,7 +2583,8 @@ where
2576
2583
/// }
2577
2584
///
2578
2585
/// fn read_user_from_stream(tcp_stream: TcpStream) -> Result<User, Box<dyn Error>> {
2579
- /// let mut de = serde_json::Deserializer::from_reader(tcp_stream);
2586
+ /// let buf_tcp_stream = BufReader::new(tcp_stream);
2587
+ /// let mut de = serde_json::Deserializer::from_reader(buf_tcp_stream);
2580
2588
/// let u = User::deserialize(&mut de)?;
2581
2589
///
2582
2590
/// Ok(u)
0 commit comments