pub struct StreamingWriter<W> { /* private fields */ }Expand description
Streaming writer for output.
Controls streaming output with the following behaviors:
- Streaming formats (json, jsonl, csv, tsv): Output rows immediately.
- Non-streaming formats (table): Buffer rows up to
buffer_limit.
§Output Boundary
- Output started: When
output_started == true(header has been written). - Buffer overflow: Returns an error prompting
--output json|csv|tsvor--limit.
Implementations§
Source§impl<W: Write> StreamingWriter<W>
impl<W: Write> StreamingWriter<W>
Sourcepub fn new(
writer: W,
formatter: Box<dyn Formatter>,
columns: Vec<Column>,
limit: Option<usize>,
) -> Self
pub fn new( writer: W, formatter: Box<dyn Formatter>, columns: Vec<Column>, limit: Option<usize>, ) -> Self
Create a new StreamingWriter.
§Arguments
writer- The output writer (e.g., stdout).formatter- The formatter to use for output.columns- Column definitions for the output.limit- Optional row limit.
Sourcepub fn with_buffer_limit(self, buffer_limit: usize) -> Self
pub fn with_buffer_limit(self, buffer_limit: usize) -> Self
Create a new StreamingWriter with a custom buffer limit.
Sourcepub fn with_quiet(self, quiet: bool) -> Self
pub fn with_quiet(self, quiet: bool) -> Self
Enable quiet mode (suppress warnings).
Sourcepub fn is_quiet(&self) -> bool
pub fn is_quiet(&self) -> bool
Check if quiet mode is enabled.
When quiet mode is enabled, status-only output (OK messages) should be suppressed.
Sourcepub fn prepare(&mut self, row_count_hint: Option<usize>) -> Result<()>
pub fn prepare(&mut self, row_count_hint: Option<usize>) -> Result<()>
Prepare the writer for output.
For streaming formats (json, jsonl, csv, tsv), immediately outputs the header. For non-streaming formats (table), defers header output.
§Arguments
row_count_hint- Optional estimated row count (unused for buffer sizing).
Sourcepub fn write_row(&mut self, row: Row) -> Result<WriteStatus>
pub fn write_row(&mut self, row: Row) -> Result<WriteStatus>
Write a row to the output.
For streaming formats, the row is output immediately. For non-streaming formats, the row is buffered.
§Returns
WriteStatus::Continue- Row was written, continue writing.WriteStatus::LimitReached- Row limit reached, stop writing.
§Note
The row is taken by ownership to avoid unnecessary cloning when buffering.
Sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
Finish output, flushing any buffered rows and writing the footer.
Sourcepub fn written_count(&self) -> usize
pub fn written_count(&self) -> usize
Returns the number of rows written.
Sourcepub fn output_started(&self) -> bool
pub fn output_started(&self) -> bool
Returns whether output has started.
Sourcepub fn buffered_bytes(&self) -> usize
pub fn buffered_bytes(&self) -> usize
Returns approximate buffered bytes.
Auto Trait Implementations§
impl<W> Freeze for StreamingWriter<W>where
W: Freeze,
impl<W> !RefUnwindSafe for StreamingWriter<W>
impl<W> Send for StreamingWriter<W>where
W: Send,
impl<W> Sync for StreamingWriter<W>where
W: Sync,
impl<W> Unpin for StreamingWriter<W>where
W: Unpin,
impl<W> !UnwindSafe for StreamingWriter<W>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more