Encodes a value as a JSON line. Serializes the item to JSON and appends a newline character. # Errors - if serialization to JSON fails - if writing to the buffer fails
(&mut self, item: T, dst: &mut BytesMut)
| 85 | /// - if serialization to JSON fails |
| 86 | /// - if writing to the buffer fails |
| 87 | fn encode(&mut self, item: T, dst: &mut BytesMut) -> Result<(), Self::Error> { |
| 88 | let mut writer = dst.writer(); |
| 89 | serde_json::to_writer(&mut writer, &item) |
| 90 | .map_err(io::Error::from) |
| 91 | .attach_opaque(item)?; |
| 92 | writeln!(writer)?; |
| 93 | Ok(()) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /// Decodes JSON lines into typed values. |