pub struct WriteContext<W: Write> {
pub writer: W,
pub current_state: Value,
pub observation_count: usize,
pub snapshot_interval: Option<usize>,
pub finish_strategy: FinishStrategy,
pub diagnostics: DiagnosticCollector,
}Expand description
Context for writing observations to an archive.
This struct is the result of the “setup phase” for both create and append
operations. Once you have a WriteContext, you can use write_observations
to add new states, then call finish to complete the operation.
Fields§
§writer: WThe writer to output JSON lines to.
current_state: ValueCurrent state of the archive (used for diffing).
observation_count: usizeNumber of observations already in the archive.
snapshot_interval: Option<usize>Optional interval for writing snapshots.
finish_strategy: FinishStrategyHow to finish the write operation.
diagnostics: DiagnosticCollectorDiagnostics collected during setup (e.g., warnings from reading existing archive).
Implementations§
Source§impl<W: Write> WriteContext<W>
impl<W: Write> WriteContext<W>
Sourcepub fn new(
writer: W,
current_state: Value,
observation_count: usize,
snapshot_interval: Option<usize>,
finish_strategy: FinishStrategy,
) -> Self
pub fn new( writer: W, current_state: Value, observation_count: usize, snapshot_interval: Option<usize>, finish_strategy: FinishStrategy, ) -> Self
Create a new write context.
Sourcepub fn with_diagnostics(
writer: W,
current_state: Value,
observation_count: usize,
snapshot_interval: Option<usize>,
finish_strategy: FinishStrategy,
diagnostics: DiagnosticCollector,
) -> Self
pub fn with_diagnostics( writer: W, current_state: Value, observation_count: usize, snapshot_interval: Option<usize>, finish_strategy: FinishStrategy, diagnostics: DiagnosticCollector, ) -> Self
Create a write context with existing diagnostics.
Sourcepub fn write_observations<P: AsRef<Path>>(
&mut self,
files: &[P],
) -> Result<usize, Vec<Diagnostic>>
pub fn write_observations<P: AsRef<Path>>( &mut self, files: &[P], ) -> Result<usize, Vec<Diagnostic>>
Write observations for a list of JSON files.
For each file:
- Reads and parses the JSON
- Diffs against current state
- Writes observation events
- Optionally writes a snapshot if interval is reached
- Updates current state
Returns the number of observations written.
Sourcepub fn finish(self) -> Result<DiagnosticCollector, Vec<Diagnostic>>
pub fn finish(self) -> Result<DiagnosticCollector, Vec<Diagnostic>>
Finish the write operation.
This flushes the writer and, for compressed append operations, performs the atomic file replacement.