incremental_writer/lib.rs
1//! # incremental-writer
2//!
3//! incremental-writer is a library which provides writers to write in different formats to files on disk, currently
4//! only JSON is supported. incremental_writer::json::IncrementalJsonWriter provides a writer that takes a File writer
5//! and incrementally writes JSON objects to an array inside that file using serde_json.
6//!
7//! Works on both Windows and Unix.
8//!
9//! It implements the write trait's write(&[u8]) and flush() as well as write_json() which takes
10//! any serialisable object and writes it to the underlying array.
11//!
12//! example:
13//! ```
14//! extern crate incremental_writer;
15//! use incremental_writer::json;
16//! use serde::{Serialize, Deserialize};
17//!
18//! fn main() {
19//! let rows: Vec<Record> = vec![0, 1, 2, 3, 4, 5, 6, 7 , 8, 9, 10]
20//! .iter()
21//! .map(|num| Record { name: String::from("Test"), detail: *num})
22//! .collect();
23//!
24//! let out = std::fs::File::create("docstest.json").unwrap();
25//!
26//! let mut writer = json::IncrementalJsonWriter::new(out);
27//! for row in rows {
28//! //the element is written to the file on each iteration
29//! //if it stops before finishing, the JSON is still valid
30//! writer.write_json(&row).unwrap();
31//! }
32//! }
33//! #[derive(Serialize, Deserialize, Debug)]
34//! struct Record {
35//! name: String,
36//! detail: u32
37//! }
38//! ```
39#![doc(html_root_url = "https://docs.rs/incremental-writer/0.1.2")]
40pub mod json;