WriteContext

Struct WriteContext 

Source
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: W

The writer to output JSON lines to.

§current_state: Value

Current state of the archive (used for diffing).

§observation_count: usize

Number of observations already in the archive.

§snapshot_interval: Option<usize>

Optional interval for writing snapshots.

§finish_strategy: FinishStrategy

How to finish the write operation.

§diagnostics: DiagnosticCollector

Diagnostics collected during setup (e.g., warnings from reading existing archive).

Implementations§

Source§

impl<W: Write> WriteContext<W>

Source

pub fn new( writer: W, current_state: Value, observation_count: usize, snapshot_interval: Option<usize>, finish_strategy: FinishStrategy, ) -> Self

Create a new write context.

Source

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.

Source

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:

  1. Reads and parses the JSON
  2. Diffs against current state
  3. Writes observation events
  4. Optionally writes a snapshot if interval is reached
  5. Updates current state

Returns the number of observations written.

Source

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.

Auto Trait Implementations§

§

impl<W> Freeze for WriteContext<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for WriteContext<W>
where W: RefUnwindSafe,

§

impl<W> Send for WriteContext<W>
where W: Send,

§

impl<W> Sync for WriteContext<W>
where W: Sync,

§

impl<W> Unpin for WriteContext<W>
where W: Unpin,

§

impl<W> UnwindSafe for WriteContext<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.