Skip to main content

ExportSink

Trait ExportSink 

Source
pub trait ExportSink {
    // Required methods
    fn write(&mut self, memory: &ExportableMemory) -> Result<()>;
    fn finalize(self: Box<Self>) -> Result<()>;
}
Expand description

Sink for exported memories.

Implementations write memories to a specific format (JSON, YAML, CSV, etc.).

§Lifecycle

  1. Create sink with output destination
  2. Call write() for each memory
  3. Call finalize() to complete the export

§Example Implementation

impl ExportSink for JsonSink {
    fn write(&mut self, memory: &ExportableMemory) -> Result<()> {
        serde_json::to_writer(&mut self.writer, memory)?;
        writeln!(self.writer)?;
        Ok(())
    }

    fn finalize(self: Box<Self>) -> Result<()> {
        self.writer.flush()?;
        Ok(())
    }
}

Required Methods§

Source

fn write(&mut self, memory: &ExportableMemory) -> Result<()>

Writes a single memory to the sink.

§Errors

Returns an error if serialization or I/O fails.

Source

fn finalize(self: Box<Self>) -> Result<()>

Finalizes the export, writing any footers and flushing buffers.

This method consumes the sink.

§Errors

Returns an error if I/O fails.

Implementors§