pub struct AntWriter<W: Write> { /* private fields */ }Expand description
Streaming .ant writer: records in, zstd-framed NDJSON out.
Call AntWriter::finish to emit the trailer and flush.
§Example
Write a small file — manifest first (via AntWriter::new), then
records, then AntWriter::finish to append the trailer with the
per-kind counts and the integrity hash:
use ant_types::{Evidence, ProjectId, TenantId, TypeName, Vertex, VertexId};
use antares_format::{AntRecord, AntWriter, Manifest, FORMAT_VERSION};
use std::collections::BTreeMap;
let manifest = Manifest {
format: "antares".into(),
version: FORMAT_VERSION.into(),
tenant_id: 1,
project_id: 1,
selection: None,
created_at: None,
producer: Some("doctest/0.1".into()),
};
// Any `std::io::Write` works; a Vec keeps the example in memory.
let mut writer = AntWriter::new(Vec::new(), manifest, 0)?;
writer.write(AntRecord::Vertex {
data: Vertex {
id: VertexId("deal_1".into()),
name: "Example Deal".into(),
label: TypeName("Demo.Deal".into()),
properties: BTreeMap::new(),
},
})?;
writer.write(AntRecord::Evidence {
data: Evidence::quick(
"ev1", TenantId(1), ProjectId(1),
"note", "n1", "example content",
),
})?;
let bytes = writer.finish()?; // appends the trailer, flushes zstd
assert!(!bytes.is_empty());Implementations§
Source§impl<W: Write> AntWriter<W>
impl<W: Write> AntWriter<W>
Sourcepub fn new(out: W, manifest: Manifest, level: i32) -> Result<Self, AntError>
pub fn new(out: W, manifest: Manifest, level: i32) -> Result<Self, AntError>
Compression level 0 = zstd default (currently 3). Levels up to 19 trade speed for size; text-heavy evidence compresses 5-10x at the default already.
Sourcepub fn write(&mut self, rec: AntRecord) -> Result<(), AntError>
pub fn write(&mut self, rec: AntRecord) -> Result<(), AntError>
Append one record. The manifest is written by AntWriter::new
and the trailer by AntWriter::finish; passing either here is
an error.
Auto Trait Implementations§
impl<W> !UnwindSafe for AntWriter<W>
impl<W> Freeze for AntWriter<W>where
W: Freeze,
impl<W> RefUnwindSafe for AntWriter<W>where
W: RefUnwindSafe,
impl<W> Send for AntWriter<W>where
W: Send,
impl<W> Sync for AntWriter<W>where
W: Sync,
impl<W> Unpin for AntWriter<W>where
W: Unpin,
impl<W> UnsafeUnpin for AntWriter<W>where
W: UnsafeUnpin,
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