pub struct CsvStreamingSink<T> { /* private fields */ }Expand description
CSV streaming sink that writes serializable items to a CSV file.
This sink writes each data item as a CSV row, handling headers automatically on the first write.
§Type Parameters
T- The type of items to write. Must implementSerialize.
§Example
ⓘ
use datasynth_output::streaming::CsvStreamingSink;
use datasynth_core::traits::{StreamEvent, StreamingSink};
let mut sink = CsvStreamingSink::<MyData>::new("output.csv".into())?;
sink.process(StreamEvent::Data(my_data))?;
sink.close()?;Implementations§
Source§impl<T: Serialize + Send> CsvStreamingSink<T>
impl<T: Serialize + Send> CsvStreamingSink<T>
Sourcepub fn new(path: PathBuf) -> SynthResult<Self>
pub fn new(path: PathBuf) -> SynthResult<Self>
Sourcepub fn with_header(path: PathBuf, header: &str) -> SynthResult<Self>
pub fn with_header(path: PathBuf, header: &str) -> SynthResult<Self>
Creates a CSV streaming sink with a pre-written header.
§Arguments
path- Path to the output CSV fileheader- The header line (without newline)
Sourcepub fn bytes_written(&self) -> u64
pub fn bytes_written(&self) -> u64
Returns the total bytes written.
Trait Implementations§
Source§impl<T: Serialize + Send> StreamingSink<T> for CsvStreamingSink<T>
impl<T: Serialize + Send> StreamingSink<T> for CsvStreamingSink<T>
Source§fn process(&mut self, event: StreamEvent<T>) -> SynthResult<()>
fn process(&mut self, event: StreamEvent<T>) -> SynthResult<()>
Processes a stream event.
Source§fn flush(&mut self) -> SynthResult<()>
fn flush(&mut self) -> SynthResult<()>
Flushes any buffered data.
Source§fn close(self) -> SynthResult<()>
fn close(self) -> SynthResult<()>
Closes the sink and releases resources.
Source§fn items_processed(&self) -> u64
fn items_processed(&self) -> u64
Returns the number of items processed.
Auto Trait Implementations§
impl<T> Freeze for CsvStreamingSink<T>
impl<T> RefUnwindSafe for CsvStreamingSink<T>where
T: RefUnwindSafe,
impl<T> Send for CsvStreamingSink<T>where
T: Send,
impl<T> Sync for CsvStreamingSink<T>where
T: Sync,
impl<T> Unpin for CsvStreamingSink<T>where
T: Unpin,
impl<T> UnwindSafe for CsvStreamingSink<T>where
T: 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