Writer

Struct Writer 

Source
pub struct Writer<'a> { /* private fields */ }
Expand description

Abstraction layer for writing UTF tables

Implementations§

Source§

impl<'a> Writer<'a>

Source

pub fn new(table_name: &'a str) -> Writer<'a>

Creates a new Writer

§Example
let writer = Writer::new("ImportantTable");
Source

pub fn end( &self, writer: &mut dyn Write, row_size: u16, row_count: u32, ) -> Result<()>

Verifies the amount of data written to the row buffer, and writes the final UTF table to the given stream.

§Example
let mut file = File::create("important-table.bin")?;
let writer = Writer::new("ImportantTable");
// ... table writing code ...
writer.end(file, 12, 1000)?:
Source

pub fn push_constant_column<T: Value>( &mut self, name: &'a str, value: &'a T, ) -> Result<()>

Adds a new constant column with the given value

§Example
let file_count = 5000u64;
let comment = "This is my comment".to_owned();
{
    let writer = Writer::new("ImportantTable");
    writer.push_constant_column("FileCount", file_count)?;
    writer.push_constant_column::<String>("Comment", &comment)?;
}
Source

pub fn push_constant_column_opt<T: Value>( &mut self, name: &'a str, value: &'a Option<T>, ) -> Result<()>

Adds a new optional constant column with the given value

§Example
let crc32: Option<u32> = Some(0);
let writer = Writer::new("ImportantTable");
writer.push_constant_column_opt("Crc", &crc32)?;
Source

pub fn push_rowed_column<T: Value>(&mut self, name: &'a str)

Adds a new rowed column

§Example
let writer = Writer::new("ImportantTable");
writer.push_rowed_column::<u64>("ID");
Source

pub fn push_rowed_column_opt<T: Value>(&mut self, name: &'a str, included: bool)

Adds a new optional rowed column

§Example
let context = WriteContext::new();
// ...
let writer = Writer::new("ImportantTable");
writer.push_rowed_column_opt::<u64>("ID", context.is_included("ID"));
Source

pub fn write_value<T: Value>(&mut self, rowed: bool, value: &'a T) -> Result<()>

Writes a value directly into the column or row buffer

§Example
for row in rows {
    writer.write_value::<u64>(true, &row.id)?;
    writer.write_value(true, &row.name)?;
}

Auto Trait Implementations§

§

impl<'a> Freeze for Writer<'a>

§

impl<'a> RefUnwindSafe for Writer<'a>

§

impl<'a> Send for Writer<'a>

§

impl<'a> Sync for Writer<'a>

§

impl<'a> Unpin for Writer<'a>

§

impl<'a> UnwindSafe for Writer<'a>

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.