use serde_json's to_writer
This commit is contained in:
parent
dbbdb8e5c0
commit
1e4b2e0adb
|
@ -46,13 +46,7 @@ pub fn to_vec(data: &Data) -> Result<Vec<u8>> {
|
||||||
/// Attempts to serialize a Data struct to something that implements the
|
/// Attempts to serialize a Data struct to something that implements the
|
||||||
/// std::io::Write trait
|
/// std::io::Write trait
|
||||||
pub fn to_writer<W: Write>(data: &Data, writer: W) -> Result<()> {
|
pub fn to_writer<W: Write>(data: &Data, writer: W) -> Result<()> {
|
||||||
let mut buf_writer = BufWriter::new(writer);
|
Ok(serde_json::to_writer(data, writer)?)
|
||||||
let vec = to_vec(data)?;
|
|
||||||
if vec.len() != buf_writer.write(&vec)? {
|
|
||||||
Err(crate::Error::NotAllBytesWritten)
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to serialize a Data struct to a file
|
/// Attempts to serialize a Data struct to a file
|
||||||
|
|
Loading…
Reference in New Issue