Skip to main content

AntReader

Struct AntReader 

Source
pub struct AntReader<R: Read> {
    pub manifest: Manifest,
    pub verified: bool,
    pub version: FormatVersion,
    pub minor_ahead: bool,
    /* private fields */
}
Expand description

Streaming .ant reader. Yields records after validating the manifest; reading through to the trailer verifies counts + hash and sets AntReader::verified.

§Example

Read back a stream, one record at a time. The reader hashes every line as it goes; when AntReader::next_record returns Ok(None) the trailer’s sha256 and per-kind counts have been checked against what was actually read:

use antares_format::{AntReader, AntRecord, AntWriter, Manifest, FORMAT_VERSION};

let mut reader = AntReader::new(bytes.as_slice())?;
assert_eq!(reader.manifest.format, "antares");

let mut records = 0;
while let Some(record) = reader.next_record()? {
    match record {
        AntRecord::Evidence { data } => assert_eq!(data.content, "example content"),
        other => panic!("unexpected record: {other:?}"),
    }
    records += 1;
}

// `Ok(None)` means the trailer was reached AND verified: its hash
// and counts matched the records streamed above.
assert!(reader.verified);
assert_eq!(records, 1);

Fields§

§manifest: Manifest

The manifest, validated during AntReader::new.

§verified: bool

Set once the trailer was seen and verified.

§version: FormatVersion

Version parsed from the manifest. Same major as this build, or new would have refused the file.

§minor_ahead: bool

The file was written by a NEWER minor than this build. Readable by policy (minors are additive-only), but it may carry record kinds this build skipped — a caller that reports completeness to a user should say so.

Implementations§

Source§

impl<R: Read> AntReader<R>

Source

pub fn new(input: R) -> Result<Self, AntError>

Open a .ant stream: decode the framing, read and validate the manifest, and apply the version compatibility policy.

Source

pub fn next_record(&mut self) -> Result<Option<AntRecord>, AntError>

Next data record; None after a VERIFIED trailer. Unknown-kind lines are skipped (forward compatibility) but still hashed.

Auto Trait Implementations§

§

impl<R> !UnwindSafe for AntReader<R>

§

impl<R> Freeze for AntReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for AntReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for AntReader<R>
where R: Send,

§

impl<R> Sync for AntReader<R>
where R: Sync,

§

impl<R> Unpin for AntReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for AntReader<R>
where R: 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.