pub struct JsonLinesWriter<W: Write> { /* private fields */ }Expand description
Streaming writer for JSONL format
Writes HEDL documents as newline-delimited JSON for efficient streaming.
§Format
Each document is written as a single JSON object followed by newline:
{"id":"1","name":"Alice"}
{"id":"2","name":"Bob"}§Examples
use hedl_json::streaming::JsonLinesWriter;
use hedl_core::Document;
use std::io::Cursor;
# fn example() -> Result<(), Box<dyn std::error::Error>> {
let mut buffer = Vec::new();
let mut writer = JsonLinesWriter::new(&mut buffer);
let doc1 = Document::new((2, 0));
writer.write_document(&doc1)?;
let doc2 = Document::new((2, 0));
writer.write_document(&doc2)?;
writer.flush()?;
# Ok(())
# }Implementations§
Source§impl<W: Write> JsonLinesWriter<W>
impl<W: Write> JsonLinesWriter<W>
Sourcepub fn write_document(&mut self, doc: &Document) -> Result<(), StreamError>
pub fn write_document(&mut self, doc: &Document) -> Result<(), StreamError>
Write a HEDL document as a JSONL entry
Converts the document to JSON and writes it followed by a newline.
§Errors
Returns error if JSON conversion or I/O write fails.
§Examples
use hedl_json::streaming::JsonLinesWriter;
use hedl_core::Document;
# fn example() -> Result<(), Box<dyn std::error::Error>> {
let mut buffer = Vec::new();
let mut writer = JsonLinesWriter::new(&mut buffer);
let doc = Document::new((2, 0));
writer.write_document(&doc)?;
# Ok(())
# }Sourcepub fn flush(&mut self) -> Result<(), StreamError>
pub fn flush(&mut self) -> Result<(), StreamError>
Flush the output buffer
Ensures all data is written to the underlying writer.
§Examples
use hedl_json::streaming::JsonLinesWriter;
use hedl_core::Document;
# fn example() -> Result<(), Box<dyn std::error::Error>> {
let mut buffer = Vec::new();
let mut writer = JsonLinesWriter::new(&mut buffer);
let doc = Document::new((2, 0));
writer.write_document(&doc)?;
writer.flush()?;
# Ok(())
# }Auto Trait Implementations§
impl<W> Freeze for JsonLinesWriter<W>where
W: Freeze,
impl<W> RefUnwindSafe for JsonLinesWriter<W>where
W: RefUnwindSafe,
impl<W> Send for JsonLinesWriter<W>where
W: Send,
impl<W> Sync for JsonLinesWriter<W>where
W: Sync,
impl<W> Unpin for JsonLinesWriter<W>where
W: Unpin,
impl<W> UnwindSafe for JsonLinesWriter<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more