Skip to main content

ContainerWriter

Struct ContainerWriter 

Source
pub struct ContainerWriter { /* private fields */ }
👎Deprecated since 0.2.0:

superseded by the .verit file: use FileBuilder (in memory) or FileWriter (on disk). A .vertc container carries no schema section, so it cannot be read without an out-of-band registry. Removed in 0.3.0 — see ADR-0002.

Expand description

Build a .vertc container from a sequence of Veritate messages. The output is a self-contained Vec<u8> you write to a file (and later mmap).

let mut w = ContainerWriter::new();
w.add(b"\x00message-a");
w.add(b"\x01message-b");
let file = w.finish();

let c = Container::parse(&file).unwrap();
assert_eq!(c.len(), 2);
assert_eq!(c.get(1).unwrap(), b"\x01message-b");

Implementations§

Source§

impl ContainerWriter

Source

pub fn new() -> ContainerWriter

Source

pub fn add(&mut self, message: &[u8]) -> &mut Self

Append one message’s bytes as the next record. Records are stored in the order added and read back by that index.

Source

pub fn len(&self) -> usize

Number of records added so far.

Source

pub fn is_empty(&self) -> bool

Source

pub fn finish(self) -> Vec<u8>

Finish the container and return its bytes: pad to the index alignment, append the index, then patch the header.

Trait Implementations§

Source§

impl Default for ContainerWriter

Source§

fn default() -> ContainerWriter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.