Skip to main content

AntWriter

Struct AntWriter 

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

Source

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.

Source

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.

Source

pub fn counts(&self) -> &Counts

Records written so far (excluding manifest/trailer).

Source

pub fn finish(self) -> Result<W, AntError>

Emit the trailer (counts + sha256 of everything before it) and finish the zstd frame. Returns the inner writer.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.