pub struct TraceWriter { /* private fields */ }Expand description
Writer for streaming trace events to a file.
Events are written incrementally, allowing large traces to be written without holding all events in memory. When compression is enabled, events are buffered and compressed in chunks.
§Example
let mut writer = TraceWriter::create("trace.bin")?;
writer.write_metadata(&TraceMetadata::new(42))?;
for event in events {
writer.write_event(&event)?;
}
writer.finish()?;Implementations§
Source§impl TraceWriter
impl TraceWriter
Sourcepub fn create(path: impl AsRef<Path>) -> TraceFileResult<Self>
pub fn create(path: impl AsRef<Path>) -> TraceFileResult<Self>
Creates a new trace file for writing with default configuration.
§Errors
Returns an error if the file cannot be created.
Sourcepub fn create_with_config(
path: impl AsRef<Path>,
config: TraceFileConfig,
) -> TraceFileResult<Self>
pub fn create_with_config( path: impl AsRef<Path>, config: TraceFileConfig, ) -> TraceFileResult<Self>
Creates a new trace file for writing with custom configuration.
§Errors
Returns an error if the file cannot be created.
Sourcepub fn write_metadata(
&mut self,
metadata: &TraceMetadata,
) -> TraceFileResult<()>
pub fn write_metadata( &mut self, metadata: &TraceMetadata, ) -> TraceFileResult<()>
Writes the trace metadata (must be called first).
This writes the file header including magic bytes, version, flags, compression mode, and the serialized metadata.
§Errors
Returns an error if writing fails or the writer was already finished.
Sourcepub fn write_event(&mut self, event: &ReplayEvent) -> TraceFileResult<()>
pub fn write_event(&mut self, event: &ReplayEvent) -> TraceFileResult<()>
Writes a single replay event.
Events are length-prefixed for streaming reads. When compression is enabled, events are buffered and written in compressed chunks.
§Errors
Returns an error if serialization or writing fails.
Sourcepub fn finish(self) -> TraceFileResult<()>
pub fn finish(self) -> TraceFileResult<()>
Finishes writing the trace file.
This flushes any remaining compressed data, updates the event count in the header, and flushes all data. Must be called to complete the file properly.
§Errors
Returns an error if flushing or seeking fails.
Sourcepub fn event_count(&self) -> u64
pub fn event_count(&self) -> u64
Returns the number of events written so far.