Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Builds a container.

use iris_format::{Builder, Container, SectionKind};

let mut builder = Builder::new("readings", 3);
let data = builder.section(SectionKind::Data, b"three rows go here".to_vec());
let bytes = builder.build()?;

let container = Container::parse(&bytes)?;
container.verify()?;
assert_eq!(container.dataset().rows, 3);
assert_eq!(
    container.section_bytes(container.section(data).unwrap()),
    b"three rows go here"
);

Implementations§

Source§

impl Builder

Source

pub fn new(name: impl Into<String>, rows: u64) -> Self

Starts a container for a dataset with this name and this many rows.

Source

pub fn schema( &mut self, encoding: SchemaEncoding, bytes: impl Into<Vec<u8>>, ) -> &mut Self

Sets the schema.

Source

pub fn section(&mut self, kind: SectionKind, bytes: impl Into<Vec<u8>>) -> u32

Adds a section and returns the id the rest of the container refers to it by.

Source

pub fn embed_decoder( &mut self, name: impl Into<String>, abi: (u16, u16), required: CapabilitySet, module: impl Into<Vec<u8>>, ) -> u32

Puts a decoder module in the container and points the dataset at it.

Returns the id of the section the module went into, which is worth having for a tool that wants to print the layout.

Source

pub fn external_decoder( &mut self, name: impl Into<String>, abi: (u16, u16), required: CapabilitySet, digest: Digest, ) -> &mut Self

Points the dataset at a decoder that lives somewhere else, named by its digest.

Source

pub fn build(&self) -> Result<Vec<u8>>

Lays the container out and returns the bytes.

§Errors

Returns crate::Error::Footer if a name or a schema is longer than the wire format can describe, which takes four gigabytes of it.

Source

pub fn build_into(&self, out: impl Write) -> Result<u64>

Lays the container out and writes it, returning how many bytes that was.

The same file as Builder::build, written rather than collected. It matters when the sections are large: a container written this way costs the sections themselves and about a kilobyte, where collecting it costs the sections twice over and briefly three times while a buffer grows. A four gigabyte dataset is the difference between a machine that can write one and a machine that cannot.

The sections still have to be in memory, because this builder holds them. That is the next thing to fix and the layout is already arranged for it: the directory is at the end, so nothing written earlier depends on anything decided later.

§Errors

Returns crate::Error::Io if the writer refused anything, and crate::Error::Footer if a name or a schema is longer than the wire format can describe.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.